This script works perfectly fine whilst I'm testing in Studio but it just doesn't work at all when I'm playing in Online mode. When the user sits in the seat, it should clone the GUI for only them to see. When they jump off, the GUI should disappear.
I know it's something to do with "LocalPlayer" on line 7. The script isn't a LocalScript, that wouldn't work with a seat. Is there something else I can do?
Here's the script:
gui = script.Parent.Controls guiClone = nil script.Parent.ChildAdded:connect(function(newWeld) char = newWeld.Part1.Parent guiClone = gui:Clone() guiClone.Parent = game.Players.LocalPlayer.PlayerGui end) script.Parent.ChildRemoved:connect(function(removeWeld) if guiClone then guiClone:Destroy() end end)
Thanks, I appreciate all answers, even if you're not 100% sure that it works.
In order to use LocalPlayer
, you have to use a LocalScript.
However, you don't need LocalPlayer
. On line 05, you are getting the player's Character
, which is just a hop away from their player:
player = game.Players:GetPlayerFromCharacter(char) guiClone = gui:Clone() guiClone.Parent = player.PlayerGui
There's nothing in this script that is local to a particular player -- it's operating a seat! So you shouldn't be thinking about how to accomplish this as a local script.