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

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

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

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

0
Use correct tabbing in the future, please. OldPalHappy 1477 — 7y
0
You didn't defined "plr." TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
-1
Answered by
wookey12 174
7 years ago
Edited 7 years ago

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
1
Everything after plr:LoadCharacter() isn't going to load. Also, you can't use LoadCharacter() in a LocalScript. Azarth 3141 — 7y
0
Hey man, don't stick that on my answer, put it on his question... wookey12 174 — 7y
1
I put it on yours because you answered it, but didn't correct the other errors. Azarth 3141 — 7y
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. wookey12 174 — 7y
Ad

Answer this question