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

If you sit, a GUI pops up?

Asked by 9 years ago

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

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 ObscureEntity 294 — 9y

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

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.

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 DeciusGalerius 20 — 9y
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. M39a9am3R 3210 — 9y
Ad

Answer this question