Log in to vote

How do I make a script that disable keys when damaged?

Asked by 15 days ago

I'm trying to make a JOJO combat game, and I want to add a stun system when you get damaged. The script I tried using makes the user not able to move for an amount of time after getting damaged, here it is:

local character = script.Parent local humanoid = character:FindFirstChildWhichIsA("Humanoid") local oldHealth = humanoid.Health local elapsed = os.clock()

humanoid:GetPropertyChangedSignal("Health"):Connect(function() if oldHealth > humanoid.Health then elapsed = os.clock() end oldHealth = humanoid.Health end)

while true do if os.clock() - elapsed > 1.3 then --duration. humanoid.WalkSpeed = 16 -- normal walk speed. else humanoid.WalkSpeed = 0 -- damage walk speed. end local delta = game:GetService("RunService").Heartbeat:Wait() end

And I want to make a version of this script where it disables a certain key (exmp: E or R) when you get damaged but I cant seem to find a solution, so any advice?

1 answer

Log in to vote
Answered by 8 days ago

Try making it say when the key is pressed, walkspeed is 0 for a little but of time. Hope that helps!


Answer this question