So i'm making a checkpoint based game, and I'm making a GUi when they touch a checkpoint, it comes up. But It doesnt, and thats because I'm not getting into the player's GUI. I've tried to access it to make the GUi visible, but I don't know how because all the players will have different names.
s = game.Workspace.Level1.SL2 --[[if s.Enabled == true then s.Enabled = false end--]] s.Enabled = false function onTouch() --yes I know, i'm to lazy to convert it to an anonymous function. local b = game.Workspace.Level1:FindFirstChild("SL1") if b ~= nil then b.Enabled = false s.Enabled = true print("Player has hit a checkpoint!") local Checkpoint = game.Players:GetChildren() local a = GetChildren():FindFirstChild("PlayerGui") if a == true then PlayerGui.Checkpoint.CheckpointBlue.Background then a.Visible = true end end end script.Parent.Touched:connect(onTouch)
Thanks!
edit1: Only 1 person will be in the game in the final version
The Touched event passes on the instance that has touched it to the connected function. If you want to get to the player's PlayerGui, you'd simply check to see whether this instance belonged to a player; if it does you'd get their player by using either FindFirstChild or, more appropriately, GetPlayerFromCharacter
function Touch(Item) if Item.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Item.Parent) then local PlayerGui = game.Players:GetPlayerFromCharacter(Item.Parent).PlayerGui end end script.Parent.Touched:connect(Touch)