How to get players server side

I need to get a player server side but I don’t know how.

Can you help

3 Likes

Like a player in specific? or just players, if you’re looking for that, then you should use PlayerAdded.

2 Likes

I am trying to get the players team and it looks for the team if a part is touched

1 Like

Could you provide me your code?

1 Like
-- SERVER SCRIPT INSIDE SERVERSCRIPTSERVICE
---> services
local TweenService = game:GetService("TweenService")

---> variables
local ball = game.Workspace:WaitForChild("Ball")
local hitparts = script.Parent

local opart = game.Workspace:WaitForChild("O")


---> main
hitparts.Touched:Connect(function(hit)
	--if players team == blue then

		ball.CFrame = CFrame.new(opart.Position)

	
end)
1 Like

You need to use: game.Players:GetPlayerFromCharacter(hit.Parent).Team, and that will do it!
or, if you’re asking for the teamcolor, then it’s the same, just that it’s property is called TeamColor.

1 Like

how do I ask for teamcolor
that worked

1 Like
-- SERVER SCRIPT INSIDE SERVERSCRIPTSERVICE
---> services
local TweenService = game:GetService("TweenService")

---> variables
local ball = game.Workspace:WaitForChild("Ball")
local hitparts = script.Parent

local opart = game.Workspace:WaitForChild("O")


---> main
hitparts.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == "Color" then
		ball.CFrame = CFrame.new(opart.Position)
	end
end)

I did that but it said

Players.Cyber_Designer.Backpack.Tool.Handle.Script:15: attempt to index nil with 'TeamColor' 
-- SERVER SCRIPT INSIDE SERVERSCRIPTSERVICE
---> services
local TweenService = game:GetService("TweenService")

---> variables
local ball = game.Workspace:WaitForChild("Ball")
local hitparts = script.Parent

local opart = game.Workspace:WaitForChild("O")


---> main
hitparts.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == "0,0,255" then
		ball.CFrame = CFrame.new(opart.Position)
	end
end)

You put a value into a string, you need to do “Blue”.

It still did not work

-- SERVER SCRIPT INSIDE SERVERSCRIPTSERVICE
---> services
local TweenService = game:GetService("TweenService")

---> variables
local ball = game.Workspace:WaitForChild("Ball")
local hitparts = script.Parent

local opart = game.Workspace:WaitForChild("O")


---> main
hitparts.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == "Really blue" then
		ball.CFrame = CFrame.new(opart.Position)
	end
end)

if it’s better I can use the name

Any errors?, could you kindly try providing a video as well please?

You can also try “if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == Color3.new(0,0,255) then”.

Oh, wait I forgot. You need to add BrickColor.new(“Really blue”), sorry about that.

You need to check if hit is a character limb or a random part within the game(or even the handle of a tool within your character):

--your code
hitparts.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end --if the part isn't a character limb, ignore
	if player.TeamColor == BrickColor.new("Really blue") then
		ball.CFrame = CFrame.new(opart.Position)
	end
end)
1 Like

Error

Players.Cyber_Designer.Backpack.Tool.Handle.Script:15: attempt to index nil with 'TeamColor' 

Nyrion there where no errors but nothing happened

Oh, that’s because your checking the tool for the teamcolor, you have to check the player.

how do I do that
aaaaaaaaaaaaaa

Try using, hit.Parent.Parent, if that doesn’t work then just slap another .Parent to it and it should work.

Players.Cyber_Designer.Backpack.Tool.Handle.Script:15: attempt to index nil with 'TeamColor' 

Could you send me the code again, sorry I’m not providing enough help.