Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so that a player cannot be a shooter/hero twice?

Asked by 6 years ago
Edited 6 years ago

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
0
It's not really something you should worry about if it only happens at the output. And if there's nothing off at your game, If I were you, I would not worry about it. Nep_Ryker 131 — 6y
0
:/ dude i have to fix the issue of people being a shooter and a hero too KawaiiX_Jimin 54 — 6y
0
they will get the gun twice and i dont want that to happen KawaiiX_Jimin 54 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
Ad

Answer this question