Hi! I’m making a game and there’s a feature where if you touch an Orb you get a power. I’ve tried making one where it gives you a healing ability and plays an animation. The animation plays, but the healing nor the debounce works. How the power works is that when you press H with a tool, it will play the animation and spawn a part where the mouse is, that part will heal the player that the person with the power is pointing at. However, when I do this, the part does not heal the player and you can spam the H key.
I believe you have forgotten to implement the blocking if-statement that is important for a debounce pattern. Note that the healing doesn’t work because of the client-server context boundaries, you’ll have to alter your design for it to work, in respect of this boundary using remotes.
This clip of your script, has no debounce at all. It is doing three checks on Hit and it shoud work as is. It should also give heath a few times in a row quickly…
The fact you’re getting nothing points to the error not being here. If health didn’t move at all it never made it here…
local trigger = script.Parent
local db = true
trigger.Touched:Connect(function(Hit)
if db and Hit.Parent:FindFirstChild("Humanoid") then db = false
Hit.Parent.Humanoid.Health +=50 task.wait(2) db = true
end
end)
local plr = game.Players.LocalPlayer
local uis = game:GetService(“UserInputService”)
local team = game:WaitForChild(“Teams”)
local heal = script.Parent.Handle.Heal
local healpartc = game.ReplicatedStorage.HealPart:Clone()
local debounce = false
local mouse = plr:GetMouse()
local function Teal()
healpartc.Parent = workspace
healpartc.Position = mouse.Hit.Position
local anim = script.Parent.Parent.Humanoid:LoadAnimation(script:FindFirstChild(“Animation”))
anim:Play()
heal.Enabled = true
wait(3)
heal.Enabled = false
end
uis.InputBegan:Connect(function(input)
debounce = true
if input.KeyCode == Enum.KeyCode.H then
local healpartc = game.ReplicatedStorage.HealPart:Clone()
and put it here:
local function Teal()
local healpartc = game.ReplicatedStorage.HealPart:Clone()
healpartc.Parent = workspace
healpartc.Position = mouse.Hit.Position
local anim = script.Parent.Parent.Humanoid:LoadAnimation(script:FindFirstChild(“Animation”))
anim:Play()
heal.Enabled = true
end
Thank you! it works a lot better. The only problem now is making the Part’s heal script, and the debounce work. Because when I type:
uis.InputBegan:Connect(function(input)
if debounce == false then debounce = true
if input.KeyCode == Enum.KeyCode.H then
Teal()
wait(5)
debounce = false
end
end
end)
the script doesn’t work at all, and then when I put it as just:
uis.InputBegan:Connect(function(input)
debounce = true
if input.KeyCode == Enum.KeyCode.H then
Teal()
wait(5)
debounce = false
end
end)
the debounce doesn’t work. I hope that I am not asking too much of you, but the help would really be appreciated.
I refactored your code into this way, while adding the solution of the guard statement that was missing from the debounce.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local heal = script.Parent.Handle.Heal
local healpartc = ReplicatedStorage.HealPart:Clone()
local mouse = player:GetMouse()
local debounce = false
local function Teal()
healpartc.Position = mouse.Hit.Position
healpartc.Parent = workspace -- Part is ONLY visible to the player, not the server
local anim = script.Parent.Parent.Humanoid:LoadAnimation(script:FindFirstChild("Animation"))
anim:Play()
heal.Enabled = true
task.wait(3)
heal.Enabled = false
end
UserInputService.InputBegan:Connect(function(input)
if debounce then -- This guard statement
return
end
if input.KeyCode == Enum.KeyCode.H then
debounce = true
Teal()
task.wait(5)
debounce = false
end
end)
For the functionality of the healing, you need to utilize remotes to make the server do the functionality. Because the current implementation is limited by the client context which isolates itself to the player who executed the method only.