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

I am trying to make a 100,000+ anthros door, but it will work in studio, not in game. Help?

Here is my script

local plr = game.Players.LocalPlayer
script.Parent.Touched:Connect(function()
if plr.leaderstats.Anthros.Value > 100000 then
local tpservice = game:GetService("TeleportService"):Teleport(997334876)
else
error("User doesn''t have 100,000 anthros, error 1.")
end
end)

It won't error when I have 0 anthros, and will not teleport me if I have 100,000+ Here is my error, It is different than the script that makes a error fire. Workspace.Part.Script:3: attempt to index upvalue 'plr' (a nil value)

1 answer

I really hope this is not a localscript

LocalPlayer can only be accessed by scripts running on the client, or localscripts. Seeing as this script is in workspace, it would not have access to this.

In order to fix this script, you need to get the part that touched the brick, see if its part of a player and get the player from Players.

script.Parent.Touched:Connect(function(Touched)
if Touched.Parent:FindFirstChild("Humanoid") then
plr=game.Players:GetPlayerFromCharacter(Touched.Parent)
if plr.leaderstats.Anthros.Value > 100000 then
local tpservice = game:GetService("TeleportService"):Teleport(997334876)
else
error("User doesn''t have 100,000 anthros, error 1.")
end
end
end)

1 comment

0

@OldBo5 This answer is correct. Just make sure that the script you are writing this in is NOT a local script.

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