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

I want to make when a player touches a part,(the GUI i made) becomes visible. What should i do?

Asked by 5 years ago
Edited 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        game.StarterGui.ScreenGui.Frame.Visible = true
    end
end)
0
get the player like local player = game.Players:GetPlayerFromCharacter(hit.Parent) and then player.PlayerGui.ScreenGui.Frame.Visible = true since server script cant access startergui WillBe_Stoped 71 — 5y
0
Make sure you're using a local script! songboy50 77 — 5y
0
I put the code in a code block. TheeDeathCaster 2368 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

A server script cannot access PlayerGui but a localscript can so you will need to insert a remote event into Replicated Storage and insert a localscript into ScreenGui and put this code inside of the server script

script.Parent.Touched:Connect(function()
    if hit.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        game.ReplicatedStorage.RemoteEvent:FireClient(Player)
    end
    end)

and put this code into the localscript

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
end)
0
Well, how do you know it's not a local script if they never specified if it was or not? DeceptiveCaster 3761 — 5y
0
Do I put the first code in the part? SuperSamyGamer please answer Ericksosa101 0 — 5y
0
Yes SuperSamyGamer 316 — 5y
0
Thanks! Ericksosa101 0 — 4y
Ad

Answer this question