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

How do you index the Player that touches the brick?

Asked by
OniiCh_n 410 Moderation Voter
10 years ago

Player touches brick; he is stored into a variable; you can access his PlayerGUI etc.

I want a GUI to be placed into the Player's PlayerGUI upon touching a brick. How do I get the player?

1 answer

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

Using the Touched event, you can have this script as well as the gui you want to show in the player.

local part = script.Parent
local gui = part.ScreenGui -- The gui inside the part
local debounce = true

part.Touched:connect(function(hit) -- The Touched event
    if debounce then debounce = false
    local model = hit.Parent
        if game.Players:findFirstChild(model.Name) and model:findFirstChild("Humanoid") then -- Is a player
        local add= gui:Clone()
        add.Parent = game.Players[model.Name].PlayerGui
        end
    wait(3)
    debounce = true 
    end
end)

**EDIT: **If you want to store the player's name, say a table then (I haven't tested this so might not work),


playersTouched = {} -- people who touched the brick. local part = script.Parent local gui = part.ScreenGui -- The gui inside the part local debounce = true part.Touched:connect(function(hit) -- The Touched event if debounce then debounce = false local model = hit.Parent if game.Players:findFirstChild(model.Name) and model:findFirstChild("Humanoid") then -- Is a player table.insert(playersTouched, model.Name) local add= gui:Clone() add.Parent = game.Players[model.Name].PlayerGui end wait(3) debounce = true end end)
Ad

Answer this question