I’m trying to get a gui to appear when a player touches a part. I’ve been trying for hours but I have no idea what is going wrong because the output doesn’t say anything at all. I’ve tried so many different ways of coding it, here’s the most recent one I’ve tried:
local plr = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
if plr then
startGame.Visible = true
end
end)
I read something about having to have a script with the gui to, in a way “approve” the script. If that is true, can someone explain and help me?
I think if you are getting player like that, that means you are using local script. If you put local script inside a part to fire Touched event it won’t. Use Server Script Instead, and you can get the player by using game.Player:GetPlayerFromCharacter(hit.Parent)
OKAY wow so, when I’m on the “server” in testing, It shows the gui but on client it won’t show. Here’s the code I currently have
local startGame = game.StarterGui.Gmae.StartGame
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
startGame.Visible = true
end
end)
You’re enabling the GUI from StarterGui that mean player need to reset to get it. Just after getting the player Go into playerGui and enable it, like that:
if hit.Parent:FindFirstChild("Humanoid") then--Make sure hit.Parent is player character
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.PlayerGui:FindFirstChild("Gmae").StartGame.Visible = true
end
end
so you just flat out want a gui that appears when someone touches it?
if you do then:
ok so make the part, have a screen gui ready, and then have a regular script. After this group all of them together, after this put this in the script:
local part = script.Parent.PARTNAMEHERE
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
if game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui:FindFirstChild(“GUINAMEHERE”) then
else
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent.GUINAMEHERE:Clone().Parent = player.PlayerGui
end
end