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

How Can I Detect What Team A Player Is On?

I Am New To Scripting In Roblox And I Want To Detect What Team A Player Is On When A Model Is Clicked.

I Have Tried Many Methods But None Work. Here Is My Script:

local clickdetector = script.Parent
local bed = script.Parent.Parent

clickdetector.MouseClick:Connect(function(Clicker)
	if Clicker.Team == "Blue" then
		print("bed clicked by " .. Clicker.Name)
		bed:Destroy()
	end
end)

pls help

1 answer

✓ Accepted answer

This should work, otherwise DM me on discord: A_Mp5#5847

-- local h = :FindFirstChild("Humanoid") (ignore this)
--local plyr = game.Players:FindFirstChild(Clicker.Parent.Name) (also ignore this)


	local clickdetector = script.Parent
	local bed = script.Parent.Parent
	 
clickdetector.MouseClick:Connect(function(Clicker)
	local plyr = game.Players:FindFirstChild(Clicker.Name) -- if this doesn't work, make it: "Clicker.Parent.Name"
		    if plyr.Team == "Blue" then
			        print("Bed clicked by " .. Clicker.Name..", on"..plyr.Team.."team!")
			        bed:Destroy()
		  end
		end)

2 comments

0

i would recommend using game:GetService("Players"):GetPlayerFromCharacter(Clicker) as the "plyr" (since display names are coming soon and it might tamper with the real username and fake username)

0

I fixed this problem it was just because i was switching teams with a localscript

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