Hello, I need help with an upcoming sword fighting game I'm making. Right now, I am working on the combat system. It is based around a number, which we will call buildup. Buildup starts at 21 and goes down by 2 each time you get hit. When it reaches a number lower than 7, you will get stunned. Right now I am working on the main part, getting stunned. I have yet to work on the hit detection, but if you look in the script, I can change a value so that it would simulate a hit (The value would go down). Anyway, while testing the script, it did not seem to work at all. Even though there were no errors in the output. I am very VERY new to scripting and would like all the help I can get (well I'm not forcing you but, you get it). Thanks in advance.
local buildup = script.Parent local hum = script.Parent.Parent.Parent:FindFirstChild("Humanoid") stunned = false if buildup.Value <= 7 then if stunned == false then stunned = true print("epic") local StunAnim = hum:LoadAnimation(script.Parent.StunAnim) StunAnim:Play() hum.WalkSpeed = 0 if stunned == true then wait(5) stunned = false StunAnim:Stop() hum.WalkSpeed = 16 buildup.Value = 21 end end end
You are only checking the value of buildup once. You require a loop or an event to continuously check what the value of buildup is.
As it appears buildup is a NumberValue or IntValue, this should work:
local buildup = script.Parent local hum = script.Parent.Parent.Parent:WaitForChild("Humanoid") --:FindFirstChild("Humanoid") stunned = false buildup.Changed:Connect(function(newValue) -- Whenever buildup's value is changed, this will get called. if newValue <= 7 then -- 'newValue' is the value buildup was previously changed to if stunned == false then stunned = true print("epic") local StunAnim = hum:LoadAnimation(script.Parent.StunAnim) StunAnim:Play() hum.WalkSpeed = 0 if stunned == true then wait(5) stunned = false StunAnim:Stop() hum.WalkSpeed = 16 buildup.Value = 21 end end end end)
EDIT
If you are changing buildup's value from local scripts, it leaves you with security vulnerabilities. I would highly recommend using RemoteEvents if a local script needs to change buildup's value, and changing the value on the server instead.
As far as I know you gotta use RemoteEvents. RemoteEvents send commands from the client to the server. To learn more, click here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events