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

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

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

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)

4 comments

0

Where would I put the code I would wan't to run?

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?

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.

0

Also, you would put any code you want to add below the 3rd line.

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