Hello!
So, I’m working on a game, which has multiple levels. You touch the teleporter and then it will fire a function within a module script, and then the module fires a RemoteEvent that will load the level.
My issue is that when I test in studio with 2 players, I’ll move the first player, it will load the level, move the player then destroy the spawn, as it should. But when I test with the second player, it won’t load the level or destroy the spawn.
I have 0 errors, any help would be much appreciated.
Any help would be much appreciated!!
Door Controller (that fires the module):
(Located in a Module within Workspace)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local LevelToLoad = ReplicatedStorage:WaitForChild("LevelToLoad")
local LoadLevelModule = require(ServerScriptService:WaitForChild("LoadLevel"))
local LoadLevel = ReplicatedStorage.RemoteEvents:WaitForChild("LoadLevel")
local Doors = script.Parent:GetChildren()
local Debounce = false
for _, Door in pairs(Doors) do
if Door:IsA("Model") then
Door:WaitForChild("Door").Touched:Connect(function(hit)
local Character = hit:FindFirstAncestorOfClass("Model")
if not Character then
return
end
local Player = game.Players:GetPlayerFromCharacter(Character)
if not Player then
return
end
if not Debounce then--and Player.Progress.Value >= Door:WaitForChild("ProgressNeeded").Value then
Debounce = true
--LevelToLoad.Value = Door:WaitForChild("Level").Value
wait(.5)
--LoadLevel:FireServer("Lvl1")
LoadLevelModule.LoadLevel(Door:WaitForChild("Level").Value, Character.Name)
end
--print(Player.Progress.Value)
end)
end
end
ModuleScript:
(Located in ServerScriptStorage)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadLevel = ReplicatedStorage.RemoteEvents:WaitForChild("LoadLevel")
function Module.LoadLevel(LevelValue, PlayerName)
LoadLevel:FireClient(game.Players[PlayerName], LevelValue, PlayerName)
end
return Module
LocalScript (Which should load the level):
(Located in StarterPlayerScripts)
local LoadLevel = ReplicatedStorage.RemoteEvents:WaitForChild("LoadLevel")
LoadLevel.OnClientEvent:Connect(function(LevelValue, PlayerName)
print(LevelValue)
local LevelToLoad = ReplicatedStorage.Levels[LevelValue]:Clone()
LevelToLoad.Parent = workspace
wait(1)
game.Players[PlayerName].Character:MoveTo(workspace[LevelValue]["Spawn"].Position)
game.Workspace.Spawn:Destroy()
end)