script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.StarterGui.ScreenGui.Frame.Visible = true
end
end)
✓ ANSWER ACCEPTED
I want to make when a player touches a part,(the GUI i made) becomes visible. What should i do?
1 answer
✓ Accepted answer
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)
4 comments
0
Well, how do you know it's not a local script if they never specified if it was or not?
0
Do I put the first code in the part? SuperSamyGamer please answer
0
Yes
0
Thanks!
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
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
Make sure you're using a local script!
I put the code in a code block.