Hi guys, this is my first ever question on here. So I'm trying to make a Camping-like game it is called Truth or Dare. All the other scripts work except for this one. The script is supposed to make a GUI pop up once a player touches a specific part. But when I touch the part, I look at the output and an error has popped up saying, "ally_playz336 is not a valid member of Players." So here is the script:
local GUI = script.Parent.ScreenGui -- You might want to change this to whatever your GUI is. script.Parent.PlayerTouched:connect(function(hit) if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then local plr = game.Players(hit.Parent.Name) if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then GUI.Clone().Parent = plr.PlayerGui end end end)
I don't know if there is anything wrong with it, because it looks fine to me. The only problem is that it won't work. Help is greatly appreciated ????
hit.Parent.Name is a part of hit.Parent. not a child (I think, correct me if im wrong), so an easier way to get the person touched would be to used GetPlayerFromCharacter.
Instead of using:
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then local plr = game.Players(hit.Parent.Name)
Try:
if hit.Parent then local plr = hit.Parent:GetPlayerFromCharacter
So the script would be:
local GUI = script.Parent.ScreenGui script.Parent.PlayerTouched:connect(function(hit) if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then local plr = hit.Parent:GetPlayerFromCharacter if plr:FindFirstChild("PlayerGui") then GUI.Clone().Parent = plr.PlayerGui end end end)
I hope that works!
Also I don't know why you need:
and not plr.PlayerGui:FindFirstChild(GUI.Name) then
But again, correct me if theres a reason. ;D
NOW AFTER EDITS OFFICIALLY WORKING!
Sorry I glitched from my other comment can you tell me if this works I think you should try the script with this
local GUI = script.Parent.ScreenGui script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if plr:FindFirstChild("PlayerGui") then GUI.Clone().Parent = plr.PlayerGui.ScreenGui end end end)
always remember to add the next child screen gui after player gui btw