Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		game.StarterGui.ScreenGui.Frame.Visible = true
	end
end)

3 comments

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

0

Make sure you're using a local script!

0

I put the code in a code block.

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.