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 a Certain team click this Part?

I'm sort of new to lua and need some help with this


script.Parent.ClickDetector.MouseClick:Connect(function(hit)
	local player = game.Workspace:FindFirstChild("Humanoid")
	local teams = game.Teams.Blue
	if player then 
		local player1 = game.players:GetPlayersFromCharacter(hit.Parent)
	if player1.Team == teams then
	print("The Blue Team Clicked This")
	end
	end
end)

2 answers

Hey! So, there are just a couple of problems with your code.

Your use of an event seems fine, and you're tackling the problem properly, the issue is mostly just syntax.

script.Parent.ClickDetector.MouseClick:Connect(function(player) -- MouseClick returns a player, not a part. My mistake :P Thankfully this only simplifies things.
	local teams = game:GetService("Teams")-- Use getservice to ensure 'Teams' exists.
	local teamBlue = teams:FindFirstChild("Blue Team")
	if(not teamBlue) then
		teamBlue = Instance.new("Team")
		teamBlue.Name = "Blue Team"
		teamBlue.Parent = teams
	end
	if player.Team == teamBlue then
		print("The Blue Team Clicked This")
	end
end)

I haven't tested this yet, so there's a chance I've made a couple of mistakes, let me know if that's the case.

Hope this helps

16 comments

0

You're looking for a humanoid in the Players service?

0

You made a mistake posted above ^ change your script

0

Nope, try reading my code again. I just stuck to his convention for calling the character 'player'. Though I suppose my comment is misleading, I'll edit it.

0

Reply was to incapaz, what mistake in particular?

0

incapaz you tell him he made a mistake then if he doesn't do anything you downvote. He is trying to help and only missed the .Character after player. A innocent typo 

0

Wait incapaz! He just used player as a variable meaning the character he didn't make a mistake at all!

0

incapaz was right I'm sorry  

0

Ahh, ignore my previous comments, I confused the event he used with Touched, haha. Worked with wrong parameters. Will edit post. Thanks for the corrections guys :)

0

No, the player object itself is passed as a parameter in MouseClick. "hit.Parent" is just the Players service, and saenae is looking for a Humanoid in the Players service.

0

@OBenjOne don't say stupid stuff. I will remove my downvote once it's removed. It should be edited now.

0

It's removed.

0

Sry

0

It does not work :(

0

Is it not compiling or is there some other issue?

0

I have tested it and does not work

0

Does a folder called 'Teams' exist in your Explorer? If not, try calling game:GetService("Teams") in the code.

Thank you man you have solved my problem

script.Parent.ClickDetector.MouseClick:Connect(function(player) -- MouseClick returns a player, not a part. My mistake :P Thankfully this only simplifies things.
        local teams = game.Teams.Blue
    if player.Team == teams then
        print("The Blue Team Clicked This")
    end
end)

I had modify it a bit but thanks for your help

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