Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script breaks after I put in a if statement?

Asked by 4 years 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 385 — 4y

1 answer

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years 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 882 — 4y
0
That works. But only in studio. IcyBlazeRB 28 — 4y
Ad

Answer this question