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

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

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

                                                                                                     --[[
    Copyright® 2015 Code Much? 
                                                                                                      --]]
--[[
    To get this script to work, you need to do one script for ONE (1) tool for every tool.  If you have any
    problems, contact CoderOfTheMonth.
--]]


local groupId = 0 -- Group Id V - Put tool in ServerStorage OR change that to Lighting and put the tool in lighting.
local tool = game.ServerStorage -- Tool
function onPlayerSpawned(player)
    if player:IsIngroup(groupId) then 
        tool:Clone().Parent = player.Backpack
    end
end

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

function onPlayerSpawned(player)
  if player:GetRankInGroup(groupId) >= 0 and  then -- Rank ID
    tool:Clone().Parent = player.Backpack
  end
end

3 comments

0

I want to add if the player is on a certain team, it will give them the tools

0

tip: add the tool to the starterpack so when the player dies, the tool doesn't get removed from the backpack.

0

I mean, I don't want it on another team.

2 answers

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.

local groupId = 0
local tool = game.ServerStorage -- Tool

function onPlayerSpawned(player)
	if player:IsInGroup(groupId) then 
		tool:Clone().Parent = player.Backpack
	end
end

game.Players.PlayerAdded:connect(function(player)
	onPlayerSpawned(player)
	player.CharacterAdded:connect(function(character)
		onPlayerSpawned(game.Players:GetPlayerFromCharacter(character))
	end)
end)

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

local groupId = 0
local tool = game.ServerStorage -- Tool

function onPlayerSpawned(player)
	if player:IsInGroup(groupId) then 
		tool:Clone().Parent = player.StarterGear
	end
end

game.Players.PlayerAdded:connect(function(player)
	onPlayerSpawned(player)
end)

Make sure that

  • the script

  • is a server-sided script

  • is located in the Workspace or ServerScriptService

  • the tool

  • is defined

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

it should work.

1 comment

0

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

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