-
What do you want to achieve?
I Made a script not so long ago, and i have problems with it. I would like to have the script working. -
What is the issue?
When i start the game in test mode or in normal game with more then 1 player, the script generates a map per player. The problem seems correlated to defining the player wrong.
This is my script:
local player = game.Players
function Return()
print("Start Return() function")
print(player)
wait(2)
print("Wait 2")
function RandomMap()
print("Function RandomMap")
RandomNum = math.random(1, 8)
end
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
game:GetService("ReplicatedStorage").Events.GetGUI:FireClient(playerr)
end)
print("GetGUI (countdown) fireclient")
wait(15)
print("wait 15")
RandomMap()
print("run RandomMap()")
print("RandomNUM:", RandomNum)
local SurfaceGUIs = game.Workspace.Lobby.SurfaceGUIs
local MapImage = SurfaceGUIs.Parent.MapImage
local Lightning = game.Lighting
print("some localz")
------------------------------------------------------------------------------|
if RandomNum == 1 then
local GUIclone = SurfaceGUIs.one:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.one:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Sound = game:GetService("SoundService").TimeUP
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
Sound.Playing = true
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
GUIclone:Destroy()
MAPclone:Destroy()
wait(10)
Return()
end -- of if
if RandomNum == 2 then
local GUIclone = SurfaceGUIs.two:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.two:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Sound = game:GetService("SoundService").TimeUP
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
Sound.Playing = true
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 3 then
local GUIclone = SurfaceGUIs.three:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.three:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 4 then
local GUIclone = SurfaceGUIs.four:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.four:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 5 then
local GUIclone = SurfaceGUIs.five:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.five:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 6 then
local GUIclone = SurfaceGUIs.six:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.six:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 7 then
local GUIclone = SurfaceGUIs.seven:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.seven:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
if RandomNum == 8 then
local GUIclone = SurfaceGUIs.eight:Clone()
GUIclone.Parent = MapImage
local MAPclone = Lightning.eight:Clone()
MAPclone.Parent = game.Workspace.Maps
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Playing
end)
game.Workspace.Playing.Value = true
wait(350)
local Event = game:GetService("ReplicatedStorage").Events.GetGUI2
Event:FireClient(player)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(player)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
playerr.Team = game.Teams.Lobby
end)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(2.5)
game:GetService("ReplicatedStorage").Events.GetPlayer.OnServerEvent:Connect(function(playerr)
local GunEvent = game:GetService("ReplicatedStorage").Events.FromBPtoFolder
GunEvent:FireClient(playerr)
end)
if player.Character:FindFirstChild("Webley Mk. IV") then
player.Character:FindFirstChild("Webley Mk. IV").Parent =
game.Workspace[player.Name][player.Name]
end
game.Workspace.Playing.Value = false
print("player killed")
GUIclone:Destroy()
MAPclone:Destroy()
print("part Destroyed")
wait(10)
Return()
print("script returned")
end -- of if
------------------------------------------------------------------------------|
end-- of Return()
Return()
This is the last version i tried to write, In this version i get the player from a RemoteEvent
P.S. I’m new with Devhub and roblox studio in general.