Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
8 years ago

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)
0
Is that the whole script? Or will I need to add my script in it? Sorry for late response DeveloperSolo 370 — 8y
0
nvm, It works. Thanks! DeveloperSolo 370 — 8y
Ad

Answer this question