So i have this gun game,there are three people:A shooter,A hero and lastly is the civilians.The whole script works fine,however one problem i have is that a player can be something twice.So when i tested,i became the shooter twice. heres the output
KawaiiX_Jimin Is the Shooter KawaiiX_Jimin Is the Shooter
How do i make it so that i would not become the shooter twice and when the player is the hero,he cannot be the shooter vice versa
heres the code
local replicatedstorage = game:GetService("ReplicatedStorage") local status = replicatedstorage:WaitForChild("StatusValue") while true do -- Intermission for i = 60,1,-1 do status.Value = "Intermission: "..i wait(1) end function teleAll(x, y, z) local pos = Vector3.new(515.98, 116.081, -211.75) for _, plr in pairs(game:GetService("Players"):GetPlayers()) do if plr.Character then plr.Character:MoveTo(pos) end end end local map = game.ServerStorage.BaseMap map:Clone().Parent = game.Workspace status.Value = "Waiting For Teleport..." wait(5) teleAll(515.98, 116.081, -211.75) players = game.Players:GetChildren() -- gets all players ChosenPlayer =players[math.random(1,#players)] -- Gets a random PLayer print(ChosenPlayer.Name.."Is the Shooter") game.ReplicatedStorage.Library["Crystal Gun"]:Clone().Parent = ChosenPlayer.Backpack ChosenPlayer2 = players[math.random(1,#players)] game.ReplicatedStorage.Library["Fire Gun"]:Clone().Parent = ChosenPlayer2.Backpack print(ChosenPlayer2.Name.."Is the Hero") for o = 180,1,-1 do status.Value = "Game in progress,Time left:"..o wait(1) end game.Workspace.BaseMap:Destroy() status.Value = "Game Over!Respawning at lobby..." end
Try this, not 100% sure it'll work though, I'm pretty new at scripting. It should stop the shooter being the hero at the same time.
local replicatedstorage = game:GetService("ReplicatedStorage") local status = replicatedstorage:WaitForChild("StatusValue") while true do -- Intermission for i = 60,1,-1 do status.Value = "Intermission: "..i wait(1) end function teleAll(x, y, z) local pos = Vector3.new(515.98, 116.081, -211.75) for _, plr in pairs(game:GetService("Players"):GetPlayers()) do if plr.Character then plr.Character:MoveTo(pos) end end end local map = game.ServerStorage.BaseMap map:Clone().Parent = game.Workspace status.Value = "Waiting For Teleport..." wait(5) teleAll(515.98, 116.081, -211.75) players = game.Players:GetChildren() -- gets all players ChosenPlayer =players[math.random(1,#players)] -- Gets a random PLayer print(ChosenPlayer.Name.."Is the Shooter") local Shooter = ChosenPlayer.Name game.ReplicatedStorage.Library["Crystal Gun"]:Clone().Parent = ChosenPlayer.Backpack ChosenPlayer2 = players[math.random(1,#players)] if ChosenPlayer2.Name ~= Shooter then game.ReplicatedStorage.Library["Fire Gun"]:Clone().Parent = ChosenPlayer2.Backpack print(ChosenPlayer2.Name.."Is the Hero") for o = 180,1,-1 do status.Value = "Game in progress,Time left:"..o wait(1) end game.Workspace.BaseMap:Destroy() status.Value = "Game Over!Respawning at lobby..." end