Trying to teleport players to a different place if they have enough points

You can write your topic however you want, but you need to answer these questions:

  1. Im trying to make it so if a player has enough points they can tp to a diff place but if they dont a GUI pops up. I have no idea whats wrong with it, it says somthing is wrong with line 9 here is a screenshot
    image
    ive tried having it just tp and it worked, ive tried making it print the players name and that worked but for some reason, it dont know what leaderstats is, i have a saving leaderstats on spelt exactly the same. here is the code
local Silver = script.Parent.Parent.Parent.TeleportTwo.PartTwo

script.Parent.Touched:Connect(function(hit)
	if hit.Parent ~= nil then
		local nam = hit.Parent
		local Pname = game.Players:FindFirstChild(nam)
		wait(0.1)
		
		if Pname.leaderstats.Points >= 90 then
			nam:MoveTo(Silver.Position)
		else
			game.StarterGui.PopUp.One.Enabled = true
		end
	end
end)

You haven’t provided any stack traces or what is going wrong except “something is wrong on Line 9” - and I have no idea what line 9 is (relative to your main script? or Line 9 in the code snippet you’ve sent?)

Can you please provide that information so I can help you. (Also, if you want people to read your thread, name it something descriptive - not just “I need help”)

1 Like

In your script you check if the part that touched the block has a parent, not if the part is a character. You should make sure that the object is a character before trying to access it’s player and leaderstats.

As an alternative, you can change your if statement to

if Pname and Pname.leaderstats.Points >= 90 then

sadly this did not work, thank you for trying you best though!

If you would like to get your script working, it would be worth providing the information I have requested, as it is physically impossible to assist you with the information you have provided.

This is inefficient, use GetPlayerFromCharacter()

if hit.Parent:FindFirstChild('Humanoid') ~= nil then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local name = player.Name
end

You want to be getting the Player’s PlayerGui, StarterGui is just a service

player:WaitForChild('PlayerGui').PopUp.One.Enabled = true
1 Like

Can you take a screenshot of the error? You might be new here but showing us a picture of the explorer does nothing for us.

I am so sorry, I really dont know how to ask for help, can you like tell me what you need? and all that the thing is saying is that there is somthing wrong with line 9 and its about the leaderstats

Can you please tell us what the error on line 9 says. It should say something in the output window, not just “Somethings not working on line 9”

1 Like

Copy and paste the whole error.

if Pname.leaderstats.Points >= 90 then

Should be

if Pname.leaderstats.Points.Value >= 90 then
2 Likes

if Pname.leaderstats.Points.Value