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

How do I fix my GUI script?

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.

1 answer

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.

1 comment

0

Great answer, took you less than 3 minutes to respond. It seems to make sense but I'm just testing it now. Thanks!

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