Im currently making a script that loads a stadium when a soccer game starts. In the script the part that makes the stadium load in workspace works. But theres a part that handles the start of the game, there is a remote event that gets fired and freezes the players and an other remote events that makes appear a gui with a 5 second timer. When the timer hits 0, a remote event gets fired and goes back in the script that loads the stadium. When the script that loads the stadium receives it, it fires an other remote event that makes the player able to move. Now going back to the 5 second timer, there is one last remote event that gets fired, and thats the one that tells the stadium loading script that the game will start. When the stadium loading script receives the signal to start the match, the script destroys itself.
Now these are my problems that I cant find a solution to: the part that is supposed to freeze the player and then make him move, doesnt work. The script doesnt show any errors in the output. If you could help me, i would appreciate it. Thanks for helping if you can.
This is the script that loads the stadium (script in ServerScriptService)
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local StadiumLocation = workspace:WaitForChild("StadiumLocation")
local Players = game:GetService("Players")
local PlayerNotToKill = PlayerObj
local blueSpawn
local redSpawn
game.ReplicatedStorage.LoadStadium.OnServerEvent:Connect(function()
local StadiumFolder = ServerStorage.StadiumFolder:GetChildren()
for _, FutStadium in ipairs(StadiumFolder) do
local NewStadium = FutStadium:Clone()
FutStadium.Parent = StadiumLocation
end
print("Stadium has loaded")
game.ServerScriptService.GameScript.Enabled = true
wait(2)
for _,plr in next, game:GetService("Players"):GetPlayers() do
if plr.Character and plr ~= PlayerNotToKill then plr.Character:BreakJoints()
end
end
wait(0.1)
blueSpawn = workspace.StadiumLocation.FutStadium.SoccerThings.Team1Spawn
redSpawn = workspace.StadiumLocation.FutStadium.SoccerThings.Team2Spawn
for index, player in ipairs(Teams["Blue"]:GetPlayers()) do
local character = player.Character or player.CharacterAdded:Wait()
character.PrimaryPart.CFrame = blueSpawn.CFrame
end
for index, player in ipairs(Teams["Red"]:GetPlayers()) do
local character = player.Character or player.CharacterAdded:Wait()
character.PrimaryPart.CFrame = redSpawn.CFrame
end
wait(0.1)
game.ReplicatedStorage.FreezePlayer:FireAllClients()
game.ReplicatedStorage.MatchStartTimer:FireAllClients()
game.ReplicatedStorage.MoveServerGuiPlayer.OnServerEvent:Connect(function()
game.ReplicatedStorage.MovePlayer:FireClient()
end)
game.ReplicatedStorage.StartMatch.OnServerEvent:Connect(function()
print("Script success, destroying script")
wait(0.1)
print("Script destroy success")
script:Destroy()
end)
end)
This is the 5 second timer (this is a localscript thats in a gui)
local StarterGui = game:GetService("StarterGui")
local MatchStartTimerGui = StarterGui.MatchStartTimer
local MatchStartTimerPlrGui = game.Players.LocalPlayer.PlayerGui.MatchStartTimer
game.ReplicatedStorage.MatchStartTimer.OnClientEvent:Connect(function()
MatchStartTimerGui.Enabled = true
MatchStartTimerPlrGui.Enabled = true
local time = 5
for i = 1, 5 do
wait(1)
time = time - 1
script.Parent.Text = "Match starting in: "..tostring(time)
end
wait(0.1)
game.ReplicatedStorage.MoveServerGuiPlayer:FireServer()
game.ReplicatedStorage.StartMatch:FireServer()
script.Parent.Text = "GOO!!"
wait(2)
MatchStartTimerGui:Destroy()
MatchStartTimerPlrGui:Destroy()
print("MatchStartTimerPlrGui deleted from StarterGui")
end)
This is the script that makes the player freeze and move ( LocalScript in a StarterCharacter in starterPlayer)
local GameCountDownPlrSpeed = 0
local GameCountDownPlrJump = 0
local StartingMatchPlrSpeed = 16
local StartingMatchPlrJump = 50
local Humanoid = script.Parent.Humanoid
game.ReplicatedStorage.FreezePlayer.OnClientEvent:Connect(function()
if Humanoid then
Humanoid.WalkSpeed = (GameCountDownPlrSpeed)
Humanoid.JumpPower = (GameCountDownPlrJump)
end
end)
game.ReplicatedStorage.MovePlayer.OnClientEvent:Connect(function()
if Humanoid then
Humanoid.WalkSpeed = (StartingMatchPlrSpeed)
Humanoid.JumpPower = (StartingMatchPlrJump)
end
wait(1)
script:Destroy()
end)