Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is debounce (Local Script) happening on the server???


local db = false

game.Workspace.Part.Touched:Connect(function()
         if not db then
            db = true

              print("I was stepped on :(")
              wait(10)
              db = false
        end
end)

#PROBLEM

It's going to print that everytime i step on it and wait 10 seconds before it fires again.

Now if a make a server where atleast 2 players are in; if i step on the part it waits 10 seconds, if i go to the other client and press on the part it waits???

I don't understand because it's in a local script???

1 answer

✓ Accepted answer

You are not checking if hit is from your character, other people count as parts too, solution? check if part is descendant of your character. Also if any other object touches it, it also can start because touched means that when any base part touches it, it fires. Here is a fix:

local player = game.Players.LocalPlayer -- local player

local character = player.Character or player.CharacterAdded:Wait() -- gets character

workspace:WaitForChild("Part").Touched:Connect(function(hit) -- define hit so we can work with it soon
if hit:IsDescendantOf(player.Character) then -- if part is inside of character
	print("hello")
	end
end)

Also i used waitForChild there as it is very important, if script executes faster than the part loads, it errors.

1 comment

0

OH GREAT NOW IT LOOKS LIKE IM A BEGINNER IN SCRIPTING DAMNIT! xD. All jokes aside great answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.