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

Help! How to make the GUI appear upon touching a part?

Asked by 4 years ago

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)
0
It can't appear Ziffixture 6913 — 4y
0
You’d need to get your UI from the players side as anything changed in startergui won’t change for the player, it would just stay where it is. iiMxtt_Destinyii 62 — 4y
0
So I should use a localscript? AssortedCrystal115 2 — 4y
0
Don't use local scripts as onTouch doesn't work and they only run on specific things.. SilentsReplacement 468 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
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)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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..

Answer this question