script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Points.Value > 10 then
player:LoadCharacter()
player.PlayerGui.Enabled = true
end
end)
why does GetPlayerFromCharacter returns nil?
1 answer
In your function, you have it set to where when anything touches it, it will get passed as the player and then the script will attempt to edit the Points of the object that touched it.
To fix this, you should add an if statement which checks if the object that touched it has a humanoid, if it does then you can declare the player variable.
Checking if an object has a humanoid ensures that it is a player who is touching it and so it won't return nil.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA('Humanoid') then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player:LoadCharacter()
-- rest of code
end
end
end)
However, I'm not sure what you're trying to do by 'player.PlayerGui.Enabled' because that isn't a property of PlayerGui and you cannot access PlayerGui using a ServerScript, so you should read up on RemoteFunctions here and use that instead.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thanks