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

How do I fix my GUI script?

Asked by
Sam4550 42
10 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

0
Great answer, took you less than 3 minutes to respond. It seems to make sense but I'm just testing it now. Thanks! Sam4550 42 — 10y
Ad

Answer this question