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)
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
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