What I am trying to do: I want this script to anchor the player when they click the part but nothing happens. Nothing in output what went wrong?
local AnchorDuration = 2.4 -- how long the player stays anchored
local CooldownTime = 158 -- how long until the player can be anchored again
local CooldownDistance = 10 -- how far away the player needs to walk before they can be anchored again
local UseCooldownTime = true -- whether or not you want to use a cooldown time
local UseMagnitudeCooldown = true -- whether or not you want to use a magnitude cooldown
local PlayerUniqueDebounce = {} -- player unique debounces are good for things like this
function onClicked(Object)
if not game:GetService('Players'):GetPlayerFromCharacter(Object.Parent) or not Object.Parent:FindFirstChild('HumanoidRootPart') then
print('Works (' .. Object:GetFullName() .. ').')
return
end
if PlayerUniqueDebounce[Object.Parent.Name] then
print(Object.Parent.Name .. ' is debouncing.')
return -- this ends the function if the player is debouncing
end
PlayerUniqueDebounce[Object.Parent.Name] = true
Object.Parent.HumanoidRootPart.Anchored = true
wait(AnchorDuration)
Object.Parent.HumanoidRootPart.Anchored = false
if UseCooldownTime then
wait(CooldownTime)
end
if UseMagnitudeCooldown then
repeat
wait(1)
until (Object.Parent.HumanoidRootPart.Position - script.Parent.Position).magnitude >= CooldownDistance
end
PlayerUniqueDebounce[Object.Parent.Name] = nil
end
script.Parent.MouseClick:Connect(onClicked) --click detector

4 comments
Ty very much
No problem!
Could you help me with another question in on my profile titled 'Can't find script that's causing error in the output, help?'
Sure!