#Why is the GUi popping up for everyone (local script under StarterGui)
1 messages · Page 1 of 1 (latest)
.
if its truly a local script then it really shouldn't be doing that at all unless there is a remote event or something.. (there isn't) I revised the code and left notes of things I've changed, you'll have to update your references, since i changed it according to my workspace
local players = game: GetService("Players")
local player = game.Players.LocalPlayer
local itembutton = game.Workspace:WaitForChild("touchPart")
-- ^ make sure yours is right, this is mine
-- lets put distance in the function :)
local gui = player.PlayerGui:WaitForChild("NpcQuests").MainFrame --make sure yours is right, this is mine
-- ^ putting the gui here or in the function makes no difference if this is truly a local script
local db = false
-- ^ add debounce to make sure there isn't code spam
itembutton.Touched:Connect(function(touch)
if not db then db = true
if touch.Parent:IsA("Model") then -- i find this to be more... understandable? personal preference really
if players:FindFirstChild(touch.Parent.Name) then
print("found player") -- debugging
gui.Visible = true
while true do
task.wait(0.1)
local distance = player:DistanceFromCharacter(itembutton.Position) -- the real updated distance, before you was getting the distance once and not the updated distance
-- ^ you did game.players.LocalPlayer when you already have 'player' defined in line 2
warn("DISTANCE:",distance) -- more debugging
if distance >= 10 and gui.Visible then -- you dont need == sometimes, it should pass if its true, unless you hadd "not" then it'll pass if its false, thought it's just prefrence, do what you want ofc :D
gui.Visible = false
warn("distance is more than 10.") -- even more debugging
break
end
end
end
end
task.wait(1)
db = false
print("ended.")
end
end)
he even added 2 more nests how nice of him 😭
Dude made it server somehow, what'd you do
** You are now Level 10! **
bro's so kind
if playerThatTouched==LocalPlayer then....end
i love u
** You are now Level 12! **
thx
im still learning, is this a bad thing to do? id appreciate actual feedback lol.. and it's she
i had to search what nesting is because i never heard to term until now, but am i checking too many conditions? I'm looking to actually get better 🫠 but as far as I know the script functions as wanted