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

A script that checks the player's team. i cant figure it out?

I have made a GUI where you can select your spawn its Insurgent spawn or Law Enforcement spawn. but i cant figure out the script.

local player = game.Players.LocalPlayer
local team = game.Teams.Insurgents


script.Parent.MouseButton1Click:Connect(function()
	if player.Team = team
	then
		script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-19.25, 11.564, -74.31)
	else
		script.Parent.Parent.WT.Visible = true
		wait(5)
		script.Parent.Parent.WT.Visible = false
	end
end)

The = sign from

if player.Team = team

has a red line under it

  • Logan

2 comments

0

well if you're checking something I'm pretty sure there should be two ='s

0

Im now getting this error: attempt to index upvalue 'player' (a nil value)

3 answers

✓ Accepted answer

When you are comparing things, you need to use two equals

local player = game.Players.LocalPlayer
local team = game.Teams.Insurgents


script.Parent.MouseButton1Click:Connect(function()
    if player.Team == team then -- Since you are comparing the player's team with team, you need to use ==
        script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-19.25, 11.564, -74.31)
    else
        script.Parent.Parent.WT.Visible = true
        wait(5)
        script.Parent.Parent.WT.Visible = false
    end
end)

2 comments

0

Im now getting this error: attempt to index upvalue 'player' (a nil value)

0

Thanks. and as of the Error: i had to use a local script

I haven't tested this but this should work.

local player = game.Players.LocalPlayer
local team = game.Teams.Insurgents


script.Parent.MouseButton1Click:Connect(function()
    if player.Team == team
    then
end
        script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-19.25, 11.564, -74.31)
    else
        script.Parent.Parent.WT.Visible = true
        wait(5)
        script.Parent.Parent.WT.Visible = false
    end
end)

The team is always stored in the player. You change the team like this:

player.TeamColor = team.TeamColor

Plus, you can't change the team from the local script. You need to use a remote event. Do something like the following

GUI code:

--Important variables
local teams = game:GetService("Teams")
local insurgents = teams:WaitForChild("Insurgents")

--The remote event
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer(insurgents)
end)

In ServerScriptService, put this inside a script:

local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("RemoteEvent")

function changeTeam(player,team)
	player.TeamColor = team.TeamColor
end

Tell me if this doesn't work and I'll check it.

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