Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a Certain team click this Part?

Asked by 5 years ago

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

Log in to vote
0
Answered by
saenae 318 Moderation Voter
5 years ago
Edited 5 years ago

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

0
You're looking for a humanoid in the Players service? User#19524 175 — 5y
0
You made a mistake posted above ^ change your script OBenjOne 190 — 5y
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. saenae 318 — 5y
0
Reply was to incapaz, what mistake in particular? saenae 318 — 5y
View all comments (12 more)
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  OBenjOne 190 — 5y
0
Wait incapaz! He just used player as a variable meaning the character he didn't make a mistake at all! OBenjOne 190 — 5y
0
incapaz was right I'm sorry   OBenjOne 190 — 5y
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 :) saenae 318 — 5y
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. User#19524 175 — 5y
0
@OBenjOne don't say stupid stuff. I will remove my downvote once it's removed. It should be edited now. User#19524 175 — 5y
0
It's removed. User#19524 175 — 5y
0
Sry OBenjOne 190 — 5y
0
It does not work :( jayfig04 2 — 5y
0
Is it not compiling or is there some other issue? saenae 318 — 5y
0
I have tested it and does not work jayfig04 2 — 5y
0
Does a folder called 'Teams' exist in your Explorer? If not, try calling game:GetService("Teams") in the code. saenae 318 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question