Hey Devs,
I am trying to make a game like plates of fate/ witching hour, however somehow the code to spawn the plates is not working.
I have tried to re-write the script however it is not working, I have no errors in the output and it was working until I put the event function.
Thank you for reading, here is the code
local GD = game.ReplicatedStorage.GameData
local Assets = game.ServerStorage.Assets
local Folder = game.Workspace.Folder
local TweenService = game:GetService("TweenService")
local Status = GD.Status
local PlayersInGame = {}
local Settings = {
Intermission = 20,
PlayersNeeded = 0,
TimeBetweenEvents = 5,
RoundInProgress = GD.RoundInProgress
}
local function CalculatePlayers()
local NumberOfPlayers = #game.Players:GetPlayers()
return NumberOfPlayers
end
local function Events(player)
local RandEvent = math.random(1,2)
local Plate = player.Character:FindFirstChild("PlateValue")
if RandEvent == 1 then
local Shrink = math.random(1,5)
Status.Value = player.Name.."plate has shrunk by"..Shrink.." studs"
local ShrinkInfo = TweenInfo.new(
0.75,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TweenService:Create(Plate, ShrinkInfo, {Size = Plate.Size - Vector3.new(Shrink, 0, Shrink)}):Play()
elseif RandEvent == 2 then
local Grow = math.random(1,5)
Status.Value = player.Name.."plate has grown by"..Grow.." studs"
local GrowInfo = TweenInfo.new(
0.75,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Tween = TweenService:Create(Plate, GrowInfo, {Size = Plate.Size + Vector3.new(Grow, 0, Grow)}):Play()
end
end
local plates = Assets.Plates:Clone()
plates.Parent = game.Workspace.Folder
while wait() do
if CalculatePlayers() > Settings.PlayersNeeded then
for i,v in pairs(Folder:GetChildren()) do
if v then
v:Destroy()
end
end
for i = Settings.Intermission,1,-1 do
Status.Value = "Intermission in "..i.." seconds"
wait(1)
end
Status.Value = "Game is ready to begin"
Settings.RoundInProgress.Value = true
wait(5)
for KeyValue, player in pairs(game.Players:GetPlayers()) do
if player.Character:FindFirstChild("Humanoid") then
if player.Character.Humanoid.Health >= 1 then
table.insert(PlayersInGame, KeyValue, player)
player.Team = game.Teams.Playing
for i, v in pairs(plates:GetChildren()) do
if v.Settings.OwnerOfPlate.Value == "None" and not player.Character:FindFirstChild("PlateValue") then
v.Settings.OwnerOfPlate.Value = player.Name
player.Character.HumanoidRootPart.CFrame = v.CFrame * CFrame.new(0, 2, 0)
local platevalue = Instance.new("ObjectValue")
platevalue.Parent = player.Character
platevalue.Value = v
platevalue.Name = "PlateValue"
end
end
end
end
end
for i, v in pairs(plates:GetChildren()) do
if v.Settings.OwnerOfPlate.Value == "None" then
v:Destroy()
end
end
wait(5)
repeat
if #PlayersInGame >= 1 then
for i = Settings.TimeBetweenEvents,1,-1 do
Status.Value = "next event is in "..i.." seconds"
wait(1)
end
local Value = math.random(1, #PlayersInGame)
local RandPlayer = PlayersInGame[Value]
Events(RandPlayer)
wait(5)
else
for i, v in pairs(PlayersInGame) do
table.remove(PlayersInGame, i)
end
end
until Settings.RoundInProgress.Value == false
else
Status.Value = "Need more players to begin..."
end
end