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

Button is not checking player's leaderstats after they click it?

So I need this button to check the player's leader stats before it teleports them to the map but it says "attempt to index nil with parent" pls help

local tp = script.Parent
local TeleportService = game:GetService("TeleportService")

tp.MouseButton1Click:Connect(function(click)
if game:GetService("Players")(click.Parent.Name).leaderstats.Exp >= 30000 then
print("yay")
local lobby = 4975824844
 TeleportService:Teleport(lobby)
end
end)

3 comments

0

where is this script located? Is it local script or server script?

0

local script and its the child of the button

0

Try adding '.Value' after 'leaderstats.Exp'.

2 answers

✓ Accepted answer

You should use a RemoteEvent for this.

Local Script:

local tp = script.Parent
local RemoteEvent = game.ReplicatedStorage.RemoteEvent

tp.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer()
end)

Server Script:

local TeleportService = game:GetService("TeleportService")

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
	if Player.leaderstats.Exp.Value >= 30000 then
		local Lobby = 4975824844
		TeleportService:Teleport(Lobby, Player)
	end
end)

2 comments

0

what do i name the remote event?

0

You can name it whatever you want but then you change the ServerScript to say "game.ReplicatedStorage.Your name of the event.OnServerEvent:Connect(function(Player)"

This should work but in case it says leaderstats isn't a part of player use waitforchild

local tp = script.Parent
local TeleportService = game:GetService("TeleportService")

tp.MouseButton1Click:Connect(function(click)
if game:GetService("Players")[click.Name].leaderstats.Exp >= 30000 then --
print("yay")
local lobby = 4975824844
 TeleportService:Teleport(lobby)
end
end)

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