Hi, I would like to know what should be added to my script as the "GUI" just appear without touching the part and that's not I am trying to achieve.
Any help would be great! Thanks.
Here's what i tried to make this work.
local function onTouch(hit) if (hit.Parent:findFirstChild("Huamanoid")~= nil) then local Shop = game.StarterGui.Shop.Frame Shop:TweenPosition(UDim2.new(0.288,0,0.218,0),"Out","Elastic",0.5,true) end end script.Parent.Touched:Connect(onTouch)
local function onTouch(hit) if (hit.Parent:findFirstChild("Huamanoid")~= nil) then local Shop = game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.Shop.Frame Shop:TweenPosition(UDim2.new(0.288,0,0.218,0),"Out","Elastic",0.5,true) end end script.Parent.Touched:Connect(onTouch)
Explanation
You've spelled Humanoid
to Huamanoid
. That's why it isn't appearing and the script isn't continuing from that line. If fixing it still doesn't work, here is the solution down below.
** Solution **
First of all, make sure that the part ( you want to touch for a GUI to appear) is named TouchPart
for better referencing and to avoid confusion.
Also, make sure to insert a Remote Event
into Replicated Storage
as we'll be firing that to a client later on and make sure it's named TouchEvent.
That being done, remove the scripts that are dealing with the part's touch. Now, insert a script into ServerScriptService
as it handles all the normal scripts.
The script in the ServerScriptService
should be as follows:
game.Workspace.TouchPart.Touched:Connect(hit) -- Touched event if game.Players:GetPlayerFromCharacter(hit.Parent) then game.ReplicatedStorage.TouchEvent:FireClient( game.Players:GetPlayerFromCharacter(hit.Parent)) -- Fires the RemoteEvent to a client so that other players won't see it when you touch it.. end end)
Now, insert a local script
inside the Screen GUI, not inside its descendant. The local script
would be as follows.
game.ReplicatedStorage.TouchEvent.OnClientEvent:Connect(function() script.Parent.Frame.Visible = not script.Parent.Frame.Visible -- Remove the frame from both sides and name it to something in your Screen Gui to appear. end)
^^ The reason I'm using not script.Parent.Frame.Visible
is because of that whenever a player leaves the part, the GUI disappears which is really efficient if you ask me..