Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script breaks after I put in a if statement?

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)

1 comment

0

Yoy never change the value of "active", it's always false, why do you have the "else if" on line 33?

1 answer

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.

  

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.

2 comments

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"

0

That works. But only in studio.

This discussion is preserved as it was. New answers, comments, and votes are closed.