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

Why does this script stop doing anything after line 1?

So I made this script inside a VehicleSeat for a vehicle I'm making. I'm trying to acces the players PlayerGui to set a Gui to visible. After some research on this very site I found the best way of doing this was to use "game.Players:GetPlayerFromCharacter()". However, after the script does this, it refuses to do anything else

Script code:


local Player = game.Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)

print("ANYTHING")

To simplify my problem, this is the code. It does not actually print anything. Nothing after line 1 works, including things involving the "Player" variable. I have tried "while true do" loops, functions, but nothing seems to give any output.

I use "script.Parent.Occupant.Parent" because "script.Parent.Occupant" would give me the Humanoid of the player, not the player itself.

I have another script in this VehicleSeat, which also uses GetPlayerFromCharacter, this script does give an output, but is only able to acces the GUI itself, and not any objects inside of it???

Can someone please explain to me why the first script will not do anything after line 1?

1 answer

✓ Accepted answer

Well, I don’t think that a player is sitting in the chair when the script starts. The function never returns anything, causing your script to wait and wait and wait. Try using the following method instead:

script.Parent:GetPropertyChangedSignal(“Occupant”):Connect(function()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)

	print(player.Name)
end)

Hope this helped!

2 comments

0

It did help! Thanks

0

Glad to hear it helped, but could you mark my answer as correct please?

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