Hello, So I am working on a battle-type game and I’m stuck on the part to get the players to the battle area.
What I’m hoping to do is make it teleport the number of players in the table to the battle area player points and make the battle area and players only visible to the players that are playing.
–ServerScript
--Objects
local Parent = script.Parent
local Players = game.Players
local MainParent = script.Parent.Parent
local Walls = MainParent:FindFirstChild("Walls")
local PlayerPoint = MainParent:FindFirstChild("PlayerPoint")
local LeavePoint = MainParent:FindFirstChild("PlayerLeavePoint")
local Info = PlayerPoint:FindFirstChild("PlayerCount")
local ConfigFolder = MainParent:FindFirstChild("Configuration")
local MaxPlayers = ConfigFolder.MaxPlayers
local EventFolder = game.ReplicatedStorage:FindFirstChild("Events")
local BattleEvent = EventFolder:FindFirstChild("BattleEvent")
local LeaveEvent = EventFolder:FindFirstChild("LeaveEvent")
local StartBattleEvent = EventFolder:FindFirstChild("StartBattle")
local BattleAreaFolder = game.ReplicatedStorage:FindFirstChild("BattleAreas")
--Values
local PlayersWaiting = {}
local CountdownRunning = false
--Functions
local function RunCountdown()
CountdownRunning = true
for i = 10, 0, -1 do
Info.Frame.Timer.Text = i
task.wait(1)
if #PlayersWaiting< 1 then
CountdownRunning = false
Info.Frame.Timer.Text = 0
return
end
end
for i, plr in pairs(PlayersWaiting) do
if plr.Character then
plr.Character.PrimaryPart.CFrame = workspace.GrassBattleArea.PlayerPoint1.CFrame -- This is jsut for testing
StartBattleEvent:FireClient(plr)
end
end
CountdownRunning = false
end
Parent.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
local IsWaiting = table.find(PlayersWaiting, player)
if player and not IsWaiting and #PlayersWaiting < MaxPlayers.Value then
table.insert(PlayersWaiting, player)
Info.Frame.Amont.Text = #PlayersWaiting.. "/3 Players"
player.Character.PrimaryPart.CFrame = PlayerPoint.CFrame
BattleEvent:FireClient(player, MainParent.Name)
if not CountdownRunning then
RunCountdown()
end
end
end)
LeaveEvent.OnServerEvent:Connect(function(player)
local IsWaiting = table.find(PlayersWaiting, player)
if IsWaiting then
table.remove(PlayersWaiting, IsWaiting)
end
Info.Frame.Amont.Text = #PlayersWaiting.. "/3 Players"
if player.Character then
player.Character.PrimaryPart.CFrame = LeavePoint.CFrame
end
end)
–LocalScript
--Objects
local EventFolder = game.ReplicatedStorage:FindFirstChild("Events")
local BattleEvent = EventFolder:FindFirstChild("BattleEvent")
local LeaveEvent = EventFolder:FindFirstChild("LeaveEvent")
local StartBattleEvent = EventFolder:FindFirstChild("StartBattle")
local BossBattleFolder = workspace:FindFirstChild("BattleAreas")
local Cam = workspace.CurrentCamera
local TS = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
local MainParent = script.Parent
local BattleScren = MainParent:FindFirstChild("BattleScreen")
local LeaveButton = MainParent:FindFirstChild("LeaveButton")
local BattleAreaFolder = game.ReplicatedStorage:FindFirstChild("BattleAreas")
--Values
local BattleCooldown = false
local IsBatting = false
local Time = 1
local CountdownTime = 20
local Name = 0
--Functions
BattleEvent.OnClientEvent:Connect(function(Name)
--Cam Edits
repeat wait()
Cam.CameraType = Enum.CameraType.Scriptable
until Cam.CameraType == Enum.CameraType.Scriptable
--BattleArea Edits
local BossBattle = BossBattleFolder:FindFirstChild(Name)
local CamToGo = BossBattle:FindFirstChild("CamPart")
--CamTween
local Goal = {CFrame = CamToGo.CFrame}
local CamInfo = TweenInfo.new(Time, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local CamTween = TS:Create(Cam, CamInfo, Goal):Play()
--Leave Function
wait(1)
LeaveButton.Visible = true
LeaveButton.Activated:Connect(function()
--Cam Edits
repeat wait()
Cam.CameraType = Enum.CameraType.Custom
until Cam.CameraType == Enum.CameraType.Custom
--Button Edits
LeaveButton.Visible = false
local Name = BossBattle.Name
LeaveEvent:FireServer(Name)
end)
end)
--Battle Start Event
StartBattleEvent.OnClientEvent:Connect(function()
--Cam Edits
repeat wait()
Cam.CameraType = Enum.CameraType.Custom
until Cam.CameraType == Enum.CameraType.Custom
--Button Edits
LeaveButton.Visible = false
end)
If you would like any more information the the idea I’m thinking please ask.
Thanks for any help.