How do I solve this problem? GUI appearing on everyone’s screen

Greetings!

I’m currently having trouble with my script. So, I’ve made a Beverage Machine that when a player touches the machine, a Gui will appear.

I’m using the PlayerGui to tween the Gui, it was working before but I tried it earlier, the Gui now appears on every player’s screen. I also used a LocalScript for the tweening of the Gui and the LocalScript is inside the Gui. Please see the screenshots below:

image

LocalScript:

local player = game.Players.LocalPlayer

game.Workspace.BeverageTouch.Touched:Connect(function(Hit)
if Hit.Parent.Name == "Empty Beverage Cup" then
player.PlayerGui.BeverageGUI.Frame:TweenPosition(UDim2.new(0.5, 0,0.499, 0))
end
end)

Now I’m trying to figure out why it’s appearing on everyone’s screen.

Hopefully, it will be figured out soon, your advice will be very much appreciated.

Thank you!

2 Likes

.Touched will fire for all the players as one player touching the part will still happen for everyone. You need to add a check so if game.Players:GetPlayerFromCharacter(hit.Parent.Parent) isn’t the LocalPlayer, then don’t tween the GUI (I’m presuming the beverage cup is a tool)

1 Like

Ah! Thank you so much! The Gui doesn’t appear on everyone’s screen now.

1 Like

No problem! Don’t forget to indent your code 4 spaces per code depth as it appears to not be in the code block.

1 Like

Yep! And the spacing just changed after I pasted it here, lol

1 Like