New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Script breaks after I put in a if statement?

Asked by 1 year ago

Everything is working fine when I don't do the if statement. I cant figure out why it down't work as soon as I put in an if Statement. Can anyone help?

math.randomseed(tick())



local rs = game:GetService("ReplicatedStorage")

local remote = rs.AnimAtEase

local animations = {03174847886}

local active = false





local function onPunchFired(plr)

if active == false then

local char = game.Workspace:FindFirstChild(plr.Name)

local humanoid = char.Humanoid

local animation = Instance.new("Animation")

animation.AnimationId = "rbxassetid://"..animations[math.random(1, #animations)]

local animTrack = humanoid:LoadAnimation(animation)

animTrack:Play()

else if active == true then

animTrack:Stop()

end

end



remote.OnServerEvent:Connect(onPunchFired)
0
Yoy never change the value of "active", it's always false, why do you have the "else if" on line 33? Spjureeedd 278 — 1y

1 answer

Log in to vote
0
Answered by
Psudar 853 Moderation Voter
1 year ago
Edited 1 year ago

I noticed a few problems. One, you used "else if" instead of "elseif", which made you have an "expected end of function" error. Another thing, you never changed the debounces back. So, I cleaned your script up a bit. Im pretty sure this works, I got no errors, but since you're most likely using group animations, I couldn't actually test it out.

```lua

function onPunchFired(plr)

if not active then -- Same as "if active == false"

active = true --change debounce 

local char = game.Workspace:FindFirstChild(plr.Name)

local humanoid = char.Humanoid

local animation = Instance.new("Animation")

animation.AnimationId = "rbxassetid://"..animations[math.random(1, #animations)]

animTrack = humanoid:LoadAnimation(animation)

animTrack:Play()

else --if active was true:

active = false

animTrack:Stop()

end

end ```

Hope that helped.

0
P.S, you got the < eof > error because you put a space between "else if" so the script thought you wanted to say "else --code end" "if --code end" Psudar 853 — 1y
0
That works. But only in studio. IcyBlazeRB 28 — 1y
Ad

Answer this question