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

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

Asked by
OldBo5 30
7 years ago
Edited 7 years ago

Here is my script

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

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

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
7 years ago

I really hope this is not a localscript

LocalPlayercan 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.

01script.Parent.Touched:Connect(function(Touched)
02if Touched.Parent:FindFirstChild("Humanoid") then
03plr=game.Players:GetPlayerFromCharacter(Touched.Parent)
04if plr.leaderstats.Anthros.Value > 100000 then
05local tpservice = game:GetService("TeleportService"):Teleport(997334876)
06else
07error("User doesn''t have 100,000 anthros, error 1.")
08end
09end
10end)
0
@OldBo5 This answer is correct. Just make sure that the script you are writing this in is NOT a local script. spyclub65 20 — 7y
Ad

Answer this question