Hi, below is my script where I’m using a remote event to fire the chosenMap to the client(which is a value). I’m sure the remote event is working properly because I’ve already tested it in the output. My problem is trying to return the chosenMap value and use it in my loadMap() function. When I call the function it returns a blank value. I’ve tried messing with the syntax but got nothing to work. Any help would be appreciated.
local function returnChosenMap()
local winner = CalculateWinner()
if winner == nil then
local chosenMap
RandomMap.OnClientEvent:Connect(function(chosenMap)
return chosenMap
end)
end
end
function loadMap()
local winner = CalculateWinner()
print(returnChosenMap())
local chosenMap = returnChosenMap()
Intermission.Text = "Map Loading..."
task.wait(UntilMapLoaded)
Intermission.Visible = false
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if winner == "Map1" or chosenMap == 1 then
HumanoidRootPart.CFrame = Maps.Map1.Spawn.CFrame + Vector3.new(0,3,0)
elseif winner == "Map2" or chosenMap == 2 then
HumanoidRootPart.CFrame = Maps.Map2.Spawn.CFrame + Vector3.new(0,3,0)
elseif winner == "Map3" or chosenMap == 3 then
HumanoidRootPart.CFrame = Maps.Map3.Spawn.CFrame + Vector3.new(0,3,0)
end
UntilRoundEnds = 180
while task.wait(1) do
MapTimer.Text = tostring(toMS(UntilRoundEnds))
MapTimer.Visible = true
UntilRoundEnds = UntilRoundEnds - 1
MapTimer.Text = tostring(toMS(UntilRoundEnds))
if UntilRoundEnds == 0 then
MapTimer.Visible = false
roundEnded()
EndOfRound:FireServer()
return
end
end
end