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

Why is my local script not able to find a model that is there?

I made this script so you can attack with this weird arm on your torso (Don't ask why)... The error it give me "Players.kittonlover101.Backpack.Pick2.LocalScript:5: attempt to index local 'character' (a nil value)". The error is on line 5. Any help would be appreciated. Also the 3rd Arm is a model with its own humanoid.

local CanAttack = true
local player = script.Parent.Parent
local playername = player.Name
local character = game.Workspace:FindFirstChild(playername)
local arm = character:WaitForChild("3rd Arm")


script.Parent.Activated:connect(function()

wait(0.1)
local attack = arm.Humanoid:LoadAnimation (script.Attack)

attack:Play()

wait(1)

attack:Stop()

end)

1 answer

You can use the Character property of Player to get their character. No need to search workspace for it.

local CanAttack = true
local plr = game:GetService("RunService"):IsClient() and game:GetService("Players").LocalPlayer or script:FindFirstAncestorWhichIsA("Player") -- you didnt specify if its a localscript or not /shrug

local char = plr.Character or plr.CharacterAdded:Wait() -- wait for character if it isnt created
local arm = char:WaitForChild("3rd Arm")

script.Parent.Activated:Connect(function()
    wait(0.1)
    local attack = char.Humanoid:LoadAnimation(script.Attack)
    attack:Play()
    wait(1)
    attack:Stop()
end)

(Sorry for any typos, I'm on phone and I rewrote your script instead of copy pasting it)

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