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

If you sit, a GUI pops up?

I know basic scripting, I just don't know all the basics. So, I can't get my script to work. The script basically should have a GUI pop up when you sit on it, and when you get off it should go away(I don't know how to do that).

script.Parent.ChildAdded:connect(function()
	game.Players.PlayerGUI.Gui.Frame.Visible = true
end)

Thanks

1 comment

0

When the humanoid sits or when the player comes in contact with a part? Because if it's the humanoid sitting you'd need to do humanoid.Changed. If it's not then you'd need to use player.Touched and player.TouchedEnded

1 answer

✓ Accepted answer

Your script shows a lack of attempt, but I can help with the solving of your problem.

You can use the ChildAdded event for the seat.

SeatLocationHere.ChildAdded:connect(function() --This should fire when a weld is placed.

end)

Now that a weld is in place (done automatically by ROBLOX), we can find the humanoid occupying the seat.

SeatLocationHere.ChildAdded:connect(function() --This should fire when a weld is placed.
	plr = game.Players:GetPlayerFromCharacter(SeatLocationHere.Occupant.Parent) --Since Occupant is the humanoid of the character, we will want to use Parent to find the character.
end)

Finally, we will want to change the GUI property to show the item as visible.

SeatLocationHere.ChildAdded:connect(function() --This should fire when a weld is placed.
	plr = game.Players:GetPlayerFromCharacter(SeatLocationHere.Occupant.Parent) --Since Occupant is the humanoid of the character, we will want to use Parent to find the character.
	plr.PlayerGui.Gui.Frame.Visible = true
end)

Next time, when posting on this site, have a better attempt at making a script, otherwise you will get downvoted and your question may get marked as Not Constructive.

2 comments

0

Thanks for the help, but I said I know basic scripting, I have not learned the ChildAdded function yet or welds. I couldn't make another attempt because in my mind what I had made should have worked. Also, if they get up, do I add a ChildRemoved function? Thanks for explaining

0

You would use the ChildRemoved Event, but here's the tricky part. You will have to get a hold of the weld that is getting removed, and find the player from that.

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