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

refresh after wait, attempt to index global 'plr' (a nil value)??

I am getting this error: attempt to index global 'plr' (a nil value)

The script I have is

wait(5)

local Pos = plr.Character:GetPrimaryPartCFrame()

plr:LoadCharacter()
plr.Character:SetPrimaryPartCFrame(Pos)

if plr.Character:FindFirstChild("ForceField") then
	plr.Character["ForceField"]:Destroy()
	print("testing")
end

it is supposed to refresh the character after 5 seconds than print testing

2 comments

0

Use correct tabbing in the future, please.

0

You didn't defined "plr."

1 answer

plr means nothing. the computer does not know what to think about it. you need to make it a variable.

local plr = game.Players.LocalPlayer

now, to stick that into context:

wait(5)
local plr = game.Players.LocalPlayer
local Pos = plr.Character:GetPrimaryPartCFrame()
                    plr:LoadCharacter()
                    plr.Character:SetPrimaryPartCFrame(Pos)
                    if plr.Character:FindFirstChild("ForceField") then
                        plr.Character["ForceField"]:Destroy()
print("testing")
end

4 comments

1

Everything after plr:LoadCharacter() isn't going to load. Also, you can't use LoadCharacter() in a LocalScript.

0

Hey man, don't stick that on my answer, put it on his question...

1

I put it on yours because you answered it, but didn't correct the other errors.

0

that doesn't matter, i'm not the one who wrote the code, i just helped him what was wrong with his code, and what he asked for. i don't want to be spoon feeding all of his code out to him for nothing.

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