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

Script teleporting player for two roles, and not teleporting one at all?

The goal of this code is two get two players, and give them the "teamValue" of either "Vip" or "Sniper" and then put the rest onto there own area.

The problem is that who ever is designated as "Sniper" will also get teleported to the spawn pads with the rest of the players, which breaks the system, and then another player wont get teleported at all, and is stuck in the lobby area.

local Players = game:GetService('Players')

while wait() do
	local players = game:GetService('Players'):GetPlayers()
	if #players >= 3 then
		
		wait(30)		
		
		local vip = table.remove(players,math.random(#players))
		local sniper = players[math.random(#players)]
		
		vip.Values:WaitForChild('teamValue').Value = 'Vip'
		local t = vip.Character:FindFirstChild("Torso")
		local h = vip.Character:FindFirstChild("Head")
		if vip.Character and vip.Character.Torso then
		t.CFrame = game.Workspace:WaitForChild('Spawns').VipSpawn.CFrame + Vector3.new(0,3.2,0)
		end
		
		sniper.Values:WaitForChild('teamValue').Value = 'Sniper'
		local t = sniper.Character:FindFirstChild("Torso")
		local h = sniper.Character:FindFirstChild("Head")
		if sniper.Character and sniper.Character.Torso then
		t.CFrame = game.Workspace.Spawns.SniperSpawn.CFrame + Vector3.new(0,3.2,0)
		end
		
		for k,v in pairs(players) do
			if v.Character and v.Values and not v.Values.teamValue == 'Vip' or 'Sniper' then
				local t = v.Character:FindFirstChild('Torso')
				if t then
					t.CFrame = game.Workspace.Spawns.GuardSpawn['GuardSpawn'..k].CFrame + Vector3.new(0,3.2,0)
				end
			end
		end
		wait(100)
		
	end
end

Thanks

1 answer

Your problem is the if statment on line 27.

When using a compound if statement, you have to define the value that is being compared each time, even if it is mutual between multiple conditions.

######note: use the ~= comparitive operator to symbolize inequality.

if v.Values.teamValue ~= 'Vip' and v.Values.teamValue ~= 'Sniper' then

1 comment

0

So dont put not for the first one?

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