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

How do I identify a player that touches a specific brick?

Asked by 4 years ago

I wan't to know this because I'm trying to add a system where if you touch a specific brick you earn or lose cash, this is my current code,

local part = script.Parent
local player = game.Players.LocalPlayer

local function onTouch(hit)

end

script.Parent.Touched:Connect(onTouch)

1 answer

Log in to vote
0
Answered by 4 years ago

You would use the GetPlayerFromCharacter() function from "Players".

local function onTouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    end
end

script.Parent.Touched:Connect(onTouch)
0
Where would I put the code I would wan't to run? Brockanthony10 19 — 4y
0
Also I wan't to define the player in the players tab not the workspace, does it identify the workspace player or the Players player? Brockanthony10 19 — 4y
0
The player in workspace is known as the character, this script defines the player located in "Players". You would put this script directly in the brick that you want touched. NoahsRebels 99 — 4y
0
Also, you would put any code you want to add below the 3rd line. NoahsRebels 99 — 4y
Ad

Answer this question