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

How do I access the players GUI when they touch something?

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

1 answer

✓ Accepted answer

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)

2 comments

0

Is that the whole script? Or will I need to add my script in it? Sorry for late response

0

nvm, It works. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.