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

Why does it say its unable to cast value to object?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

SCRIPT IN STARTERPLAYERSCRIPTS

local Player = game:GetService("Players").LocalPlayer
local PlayAnimation = game.ReplicatedStorage.PlayAnimation --It states that its "unable to cast value to object"
local StopAnimation = game.ReplicatedStorage.StopAnimation
local Debounce = false
function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        PlayEmote()
    end
end

function PlayEmote()
    if Debounce == false then
        PlayAnimation:FireServer(2471625994)
    else
        StopAnimation()
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)

SCRIPT IN SERVERSCRIPTSERVICE

game.ReplicatedStorage.PlayAnimation.OnServerEvent:Connect(function(Player,Animation)
    local Anim = game.Workspace[Player.Name].Humanoid:LoadAnimation(Animation)
    Anim:Play()
    game.ReplicatedStorage.StopAnimation.OnServerEvent:Connect(function(Player)
        Anim:Stop()
    end)
end)

HOW IT WORKS: Basically, it's supposed to load an animation when you press E on the keyboard.

2
Why are you playing animations on the server. Remotes are quite latent as it takes time for stuff to be transferred from one side to the other. Playing animations from the client will replicate, as clients have network ownership of their humanoid. It's less work for the server. User#19524 175 — 5y
3
also plz use the character property of player k thx lunatic5 409 — 5y
0
Use `local` functions :) Zafirua 1348 — 5y
0
also don't get the local player in a script theking48989987 2147 — 5y
View all comments (2 more)
0
assuming its a script cause you said "SCRIPT IN STARTERPLAYERSCRIPTS" theking48989987 2147 — 5y
0
Which line is this bug occurring at? I'd rather not scour each line of code to find similarities between them to the error you've mentioned. Additionally, @theking, it's probably a bit pedantic to assume he means Script over LocalScript, I'm sure it's just something he didn't look to clarify. SummerEquinox 643 — 5y

Answer this question