Hello, I am doing my own backrooms game to play with my friends and I prepared a startup Gui. There is a play button that fires a event, that event needs to change players position or set pivot of character to the random one of the spawns.
But before that I scripted a event that fires when player is added. So it needs to teleport players character to a safe box and lock the movement until she/he press the play button. But when I test it and switch to server side, I see I am in the map instead of spawn box and movement is locked as I want.
I tried to put print things and see what happens, it passed all the thing. No errors or information’s in the output.
Server Script
local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')
local starterGui = game:GetService('StarterGui')
local _workspace = game:GetService('Workspace')
local replicatedEvents = replicatedStorage:WaitForChild('ReplicatedEvents')
local beginGame = replicatedEvents:WaitForChild('BeginGame')
local changeMovementState = replicatedEvents:WaitForChild('ChangeMovementState')
players.PlayerAdded:Connect(function(player)
changeMovementState:FireClient(player, false)
print("Step 1")
player.CharacterAdded:Wait()
print("Step 2")
local character = player.Character
print("Step 3")
character.PrimaryPart.CFrame = _workspace.SafeSpawnBox.PrimaryPart.CFrame
print("Step Final")
end)
beginGame.OnServerEvent:Connect(function(player)
changeMovementState:FireClient(player, true)
player.CharacterAdded:Wait()
local character = player.Character
character.PrimaryPart.CFrame = _workspace.Spawns[math.random(1, #_workspace.Spawns:GetChildren())].CFrame
end)
Startup Gui Local Script
local replicatedStorage = game:GetService('ReplicatedStorage')
local players = game:GetService('Players')
local userInputService = game:GetService('UserInputService')
local replicatedEvents = replicatedStorage:WaitForChild('ReplicatedEvents')
local beginGame = replicatedEvents:WaitForChild('BeginGame')
local frame = script.Parent
local controlsbutton = frame.ControlsButton
local creditsbutton = frame.CreditsButton
local playbutton = frame.PlayButton
local firstLaunch = true
playbutton.Activated:Connect(function()
if firstLaunch then
firstLaunch = false
beginGame:FireServer()
end
playbutton.Active = false
creditsbutton.Active = false
controlsbutton.Active = false
local frame2
if frame.Parent:FindFirstChild('NewInstance') then
frame2 = frame.Parent:FindFirstChild('NewInstance')
else
frame2 = Instance.new('Frame', frame.Parent)
end
frame2.Name = "NewInstance"
frame2.BackgroundColor3 = Color3.new(0, 0, 0)
frame2.Size = UDim2.new(1, 0, 1, 0)
frame2.BackgroundTransparency = 1
frame2.ZIndex = 2
for i = 1, 0, -0.1 do
frame2.BackgroundTransparency = i
wait(0.005)
end
frame.Parent.VideoFrame:Pause()
beginGame:FireServer()
frame.Parent.Enabled = false
end)
Enable/Disable Movement Local Script
local replicatedStorage = game:GetService('ReplicatedStorage')
local players = game:GetService('Players')
local player = players.LocalPlayer
local playerScripts = player.PlayerScripts
local movementModule = require(playerScripts:WaitForChild('PlayerModule')):GetControls()
local replicatedEvents = replicatedStorage:WaitForChild('ReplicatedEvents')
local changeMovementState = replicatedEvents:WaitForChild('ChangeMovementState')
changeMovementState.OnClientEvent:Connect(function(stateBool)
if stateBool == false then
movementModule:Disable()
elseif stateBool == true then
movementModule:Enable()
end
end)