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

How to make the script say if the player is on a team then do a function? [UNSOLVED]

Asked by 10 years ago

I have no error, I want it to be a group, rank and if the player is on a certain team, they get the tools

01                                                                                                     --[[
02    Copyright® 2015 Code Much?
03                                                                                                      --]]
04--[[
05    To get this script to work, you need to do one script for ONE (1) tool for every tool.  If you have any
06    problems, contact CoderOfTheMonth.
07--]]
08 
09 
10local groupId = 0 -- Group Id V - Put tool in ServerStorage OR change that to Lighting and put the tool in lighting.
11local tool = game.ServerStorage -- Tool
12function onPlayerSpawned(player)
13    if player:IsIngroup(groupId) then
14        tool:Clone().Parent = player.Backpack
15    end
View all 28 lines...
0
I want to add if the player is on a certain team, it will give them the tools CoderOfTheMonth 0 — 10y
0
tip: add the tool to the starterpack so when the player dies, the tool doesn't get removed from the backpack. Operation_Meme 890 — 10y
0
I mean, I don't want it on another team. CoderOfTheMonth 0 — 10y

2 answers

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

You have two functions of the same name. Assuming that you're unsure which function to use, I'd opt for the first one for simplification reasons, but it really doesn't make that much of a difference.

What you should be focusing on is the PlayerAdded/CharacterAdded anonymous function.

01local groupId = 0
02local tool = game.ServerStorage -- Tool
03 
04function onPlayerSpawned(player)
05    if player:IsInGroup(groupId) then
06        tool:Clone().Parent = player.Backpack
07    end
08end
09 
10game.Players.PlayerAdded:connect(function(player)
11    onPlayerSpawned(player)
12    player.CharacterAdded:connect(function(character)
13        onPlayerSpawned(game.Players:GetPlayerFromCharacter(character))
14    end)
15end)

:GetPlayerFromCharacter() gets the player instance from the character object.

The script is pretty much saying for every player that joins the game, do this to the player.

For every character that joins the workspace, do this to the player.


You could also add it to the player's StarterGear if you don't want the script to take up activity (the activity it takes up is pretty much insignificant, but oh well).

01local groupId = 0
02local tool = game.ServerStorage -- Tool
03 
04function onPlayerSpawned(player)
05    if player:IsInGroup(groupId) then
06        tool:Clone().Parent = player.StarterGear
07    end
08end
09 
10game.Players.PlayerAdded:connect(function(player)
11    onPlayerSpawned(player)
12end)

Make sure that

  • the script

    • is a server-sided script

    • is located in the Workspace or ServerScriptService

  • the tool

    • is defined
Ad
Log in to vote
-2
Answered by
fdfxd 50
10 years ago

I don't see anything wrong with it, at all.

it should work.

0
He's not looking for bug fixes, he wants to know how he would detect if the player is on a specific team. aquathorn321 858 — 10y

Answer this question