I've tried the code below to make a gui, that is placed above the screen, move to the center of the screen. The visibility of the gui is checked.
local plr = game:GetService("Players").LocalPlayer local frame = plr.PlayerGui.mainGui.shopFrame script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then if frame.Position == UDim2.new(0.355,0,-0.4,0) then frame:TweenPosition(UDim2.new(0.355,0,0.4,0),"Out","Sine",1,true) end end end)
The code is in a normal script. (Not local or module.)
So for this, you will need to work with RemoteEvents. The remote is event is needed because you cannot get the LocalPlayer from a server script. Only a client script(local script)
OK so first create a new RemoteEvent this can be done by hovering your mouse over ReplicatedStorage and clicking the little plus button that shows up. Once you click it type RemoteEvent then click the result that comes up to add it. Once that is done you can name it whatever but I will keep it at remote event for this tutorial.
So, once you have your event you're going to need a LocalScript to detect when the server tells the client to do something from that remote event.
So put a new Local Script into StarterPlayer >> StarterPlayerScripts and we're going to write this code in it:
local replicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer local playerGui = player.PlayerGui or player:WaitForChild("PlayerGui") local shop = playerGui.mainGui local frame = shop:WaitForChild("shopFrame") remoteEvent.OnClientEvent:Connect(function() if frame.Position == UDim2.new(0.355,0,-0.4,0) then frame:TweenPosition(UDim2.new(0.355,0,0.4,0),"Out","Sine",1,true) end end)
OK so basically what that does is listens for the remote event that we put into ReplicatedStorage be called upon by the server to the client(this is a great way because it cannot be exploited!)
So for our server script go ahead and use the script you had in your part and write this new code in it:
local replicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent") script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then remoteEvent:FireClient(player) end end)
And in that script, we just check to see if a real player is touching the part and if they are then we use the FireClient to activate the remote event. We use GetPlayerFromCharacter on hit.Parent to find the character model(not the real player) and that function of Players returns the player if they exist.