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

Added Player.Teamcolour if statement, now does not work or give error. What is wrong?

Added Player.Teamcolour if statement, now does not work or give error. What is wrong?

local serverstore = game:GetService("ServerStorage")
local players = game:GetService("Players")

local cavalry = serverstore:WaitForChild("Cavalry Sword")

local groupid = 1141913

players.PlayerAdded:connect(function(player)
	if player:IsInGroup(groupid) then
		if player.TeamColor==BrickColor.new("Bright red") then	
			player.CharacterAdded:connect(function()
			cavalry:Clone().Parent = player.Backpack 
			end)
		end
	end
end)

3 comments

3

Do they spawn on "Bright red" team right when they join the game, or do they have to switch to that team when they get into the game. Because your if then statement is looking for it the player is already on Bright red, otherwise it just exits out of the if statement and ends the function.

0

Mega is right. When are they going to be on the 'Bright red' team? Because when this script runs they likely won't be on it.

0

There is several teams, you spawn on a neutral team, then use a TeamChange GUI to get onto the Bright Red team

1 answer

It looks to me like you are trying to access the ServerStorage. Players cannot access the ServerStorage, try ReplicatedStorage instead:

local serverstore = game:GetService("ReplicatedStorage")--added replicatedstorage
local players = game:GetService("Players")

local cavalry = serverstore:WaitForChild("Cavalry Sword")

local groupid = 1141913

players.PlayerAdded:connect(function(player)
	if player:IsInGroup(groupid) then
if player.TeamColor==BrickColor.new("Bright red") then  
        player.CharacterAdded:connect(function()
        cavalry:Clone().Parent = player.Backpack 
        end)
    end
 end
end)

All you need to do is move your tool into replicatedstorage. Hope I helped!

1 comment

0

LocalScripts can't access server storage, but since PlayerAdded doesn't work well in LocalScripts, we can deduce that this is a server Script.

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