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

My LocalScript works in Studio Test mode, but not in game?

Asked by 7 years ago

Here's my script:

player = game.Players.LocalPlayer
hum = player.Character.Humanoid

mouse = player:GetMouse()

animation1 = script:WaitForChild("One")
animation2 = script:WaitForChild("Two")
animation3 = script:WaitForChild("Three")
animation4 = script:WaitForChild("Four")

function endOne()
    local oneTrack = hum:LoadAnimation(animation1)
    oneTrack:Stop()
    print('animation1 successfully stopped!')
end

function endTwo()
    local twoTrack = hum:LoadAnimation(animation2)
    twoTrack:Stop()
    print('animation2 successfully stopped!')
end

function endThree()
    local threeTrack = hum:LoadAnimation(animation3)
    threeTrack:Stop()
    print('animation3 successfully stopped!')
end

function endFour()
    local fourTrack = hum:LoadAnimation(animation4)
    fourTrack:Stop()
    print('animation4 successfully stopped!')
end

enabled = true

mouse.KeyDown:connect(function(key)
    if key == "e" then -- Animation 1
        if enabled then
            enabled = false

            endTwo()
            endThree()
            endFour()
            wait()

            local animationTrack = hum:LoadAnimation(animation1)
            animationTrack:Play()

            wait(2)
            enabled = true
        end
    end
end)

mouse.KeyDown:connect(function(key)
    if key == "r" then -- Animation 2
        if enabled then
            enabled = false 

            endOne()
            endThree()
            endFour()
            wait()

            local animationTrack = hum:LoadAnimation(animation2)
            animationTrack:Play()

            wait(2)
            enabled = true
        end
    end
end)

mouse.KeyDown:connect(function(key)
    if key == "t" then -- Animation 3
        if enabled then
            enabled = false

            endOne()
            endTwo()
            endFour()
            wait()

            local animationTrack = hum:LoadAnimation(animation3)
            animationTrack:Play()

            wait(2)
            enabled = true
        end
    end
end)

mouse.KeyDown:connect(function(key)
    if key == "y" then -- Animation 4
        if enabled then

            local animationTrack = hum:LoadAnimation(animation4)
            animationTrack:Play()

            wait(2)
            enabled = true
        end
    end
end)

mouse.KeyDown:connect(function(key)
    if key == "w" then -- Stop all animations / back to normal
        if enabled then
            endOne()
        end
    end
end)

Thank you :)

0
The character and humanoid probably haven't loaded yet. Can't type a full answer right now, sorry. Basically you need to wait for them to exist before defining them. Perci1 4988 — 7y
0
okay thank you so much Perci1 :) Bless u bro God loves you SO MUCH :D shasta342 37 — 7y

Answer this question