Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 14 days ago

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

Log in to vote
1
Answered by
imKirda 731 Moderation Voter
14 days ago

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.

0
OH GREAT NOW IT LOOKS LIKE IM A BEGINNER IN SCRIPTING DAMNIT! xD. All jokes aside great answer. CaIcuIati0n 95 — 14d
Ad

Answer this question