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 make this script work with click detector instead?

Hello, I have this script but I want it to work with click instead of touch.

--

local Handle = script.Parent:WaitForChild("Handle")
local TeamName = "JAIL" 
local NewTeam = game.Teams:FindFirstChild(TeamName)

Handle.Touched:Connect(function(partHit)
    if partHit.Parent:FindFirstChild("Humanoid") and partHit.Parent ~= script.Parent.Parent then
        local Tagged = partHit.Parent
        game.Players:GetPlayerFromCharacter(Tagged).TeamColor = NewTeam.TeamColor
    end
end)

1 answer

On the explorer, place a ClickDetector below the part you want to click. ClickDetectors are clicks that work in 3D (Unlike TextButtons), and there is an event called MouseClick which you should use.

local handle = script.Parent:WaitForChild("Handle") --It is recommended you lowercase the first word, and then upper case the other words.
local teamName = "JAIL"
local newTeam = game.Teams:FindFirstChild(TeamName")

handle.MouseClick:Connect(function(click) --Instead of the part touching, you just need to click.
	--Unlike partHit.Parent, You only need to use click.

	game.Players:GetPlayerFromCharacter(click).TeamColor = newTeam.TeamColor
end)

2 comments

0

@Dovydas1118 wont work click is a player :P

0

Yeah, so it appears.

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