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

is not a valid member of workspace?

Asked by 2 years ago
Edited 2 years ago

Im making a animation script what should be activated on mouse click and must collect a plant like if you click a part.

In baseplate it works well zero error in my own game it gives me the error "kanepitaim is not a valid member of workspace" but it collects the plant. Animation side doesnt work.

Local Script (Animation):

wait(1)
local plr = game.Players.LocalPlayer

function click (plrClick)
    if plrClick and plr then
        if plrClick == plr then
            local hum = plr.Character:FindFirstChild("Humanoid")
            if hum then 
                local anim_feet = hum:LoadAnimation(workspace.kanepitaim.Animation)
              local current = anim_feet
                current:Play() 
                wait(2.5)
                current:Stop()
            end
        end
    end
end
wait(0.5)
workspace.kanepitaim.ClickDetector.MouseClick:Connect(click)

Parent Changer (Without that the animation script wont work):


wait(0.4) script.Parent.kanepitaim.Parent = game.Workspace wait(0.2) script.Parent.LocalScript.Parent = game.StarterPlayer.StarterCharacterScripts

1 answer

Log in to vote
0
Answered by 2 years ago

Maybe do something like this:

wait(1)
local plr = game.Players.LocalPlayer

function click (plrClick)
    if plrClick and plr then
        if plrClick == plr then
            local hum = plr.Character:FindFirstChild("Humanoid")
            if hum then 
                local anim_feet = hum:LoadAnimation(workspace:WaitForChild("kanepitaim"):WaitForChild("Animation"))
              local current = anim_feet
                current:Play() 
                wait(2.5)
                current:Stop()
            end
        end
    end
end
wait(0.5)
workspace.kanepitaim.ClickDetector.MouseClick:Connect(click)

What I did here, was waiting until the animation you are trying to use actually exists using :WaitForChild()

Ad

Answer this question