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

How would I make a script make a GUI visible on touch of a part?

Asked by 5 years ago

It sounds pretty simple but for some reason, I can't get it working. Could someone explain to me the steps on how I would go about doing this? (This doesn't mean make a script for me, just explain how I would make it.

1 answer

Log in to vote
1
Answered by
blockmask 374 Moderation Voter
5 years ago
Edited 5 years ago

Ok, before I explain more into this, you will need to know about the Touched event, about RemoteEvents, and most importantly, RemoteEvent.OnClientEvent.

So, let's create a function that we can use when calling the event.

function Touched(hit)

end

we need to get the humanoid from hit now so use hit.Parent:FindFirstChild("Humanoid"), and then use Players:GetPlayerFromCharacter(hit.Parent) to get the player

and we need to check if both the humanoid, and the player is here

function Touched(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            --Empty
        end
    end
end

and now we need to Fire a remote event from the server, to open the script

function Touched(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            RemoteEvent:FireClient(player, player)
        end
    end
end

And lastly, we need to call this function when the part is touched

script.Parent.Touched:Connect(Touched)

And now for the Client

function OnClientEvent(player)
    GuiObject.Visible = true
end

RemoteEvent.OnClientEvent:Connect(OnClientEvent)
0
Thanks! xXGokyXx 46 — 5y
Ad

Answer this question