script:
local raceScriptEvent = Instance.new("RemoteEvent")
raceScriptEvent.Parent = game.ReplicatedStorage
raceScriptEvent.Name = "RaceScriptEvent"
--Genorates a random number
local rand = Random.new()
function onRaceRunning (player)
--Loads player race bool values
local raceRunning = game.ServerStorage.RaceAlreadyRuning.Value
local playerIsRacing = player:WaitForChild("playerIsRacing")
if (raceRunning) then
if(not playerIsRacing.Value) then
playerIsRacing.Value = true
end
--Spawns character at beggining of race
local randPos = rand:NextInteger(1, 4)
local nameOfTarget = "RacingSpawns" .. randPos
player.Character:MoveTo(game.Workspace.RaceWay:FindFirstChild(nameOfTarget).Position)
else
playerIsRacing.Value = true
game.ServerStorage.RaceAlreadyRuning.Value = true
--Spawns character at beggining of race
local randPos = rand:NextInteger(1, 4)
local nameOfTarget = "RacingSpawns" .. randPos
player.Character:MoveTo(game.Workspace.RaceWay:FindFirstChild(nameOfTarget).Position)
local newOrb = game.ServerStorage.RacingOrb:Clone()
newOrb.Parent = game.Workspace
newOrb:MoveTo(game.Workspace.RaceWay.OrbSpawnRace.Position)
end
end
raceScriptEvent.OnServerEvent:Connect(raceScriptEvent)
