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

Why do I get this error when trying to set the parent of a character?

Asked by 2 years ago

I'm trying to make it that when someone clicks a gui it adds them to a folder so then I can teleport them to the map and stuff. Everything in my script should work in the way I see it but I keep getting this error that I dont understand:

Players.epicnmac.PlayerGui.PartySystem.Frame.Frame.TextButton.LocalScript:4: attempt to index nil with 'Parent'

My code is in a starter gui and is a local script. This is my code:

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Name
local char = player.Character
function OnClicked() 
char.Parent = game.Workspace.PlayersMap
end 

script.Parent.MouseButton1Down:connect(OnClicked)

Why does it give me an error? What do I have to do different to make it work?

0
If your confused on what PlayersMap is, its just a folder in workspace. epicnmac 63 — 2y
0
It could be because you're using .Name for the player variable which would mean that it is not an object in workspace? Not sure if that's the correct answer, but I'd try removing the .Name DarkCaveSpider 25 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Oh I managed to fix it after some troubleshooting I realized I was trying to find the character of the players name and not the player by deleting

.Name

I managed to fix it

Ad

Answer this question