I made a button that's supposed to lead your character of a cliff, but it didn't work. This is the code I used.
plr = game.Players.LocalPlayer char = plr.Character click = game.Workspace.DieButton.Button.ClickDetector click.MouseClick:Connect(function() char.Humanoid:MoveTo(game.Workspace.Die.Position) end)
and it came out with an error: Players.marioman1932.PlayerScripts.Die:5: attempt to index global 'char' (a nil value) but it's not a nil value because I made a variable for it. Please help of why it says that. Edit: Yes this is in a local script.
I think whats happening here is either:
A) The character hasnt been loaded in;
B) You might not be running this in a local script
--local script plr = game.Players.LocalPlayer char = plr.Character or plr.CharacterAdded:Wait() click = game.Workspace.DieButton.Button.ClickDetector click.MouseClick:Connect(function() char.Humanoid:MoveTo(game.Workspace.Die.Position) end)
The reason this works is because or
turns this into a conditional statement.
If Player.Character comes back as nil, it goes to the next condition, which is the CharacterAdded event. It then halts the script from continuing until theres a character loaded in.
Hopefully that helps.
https://developer.roblox.com/en-us/api-reference/property/Player/Character