So I’ve been trying to figure out how I can prevent a player from spawning until they press the play button.
Script I have for the play button and Camera:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local PlayButton = script.Parent.Play
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
PlayButton.MouseButton1Click:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
PlayButton:Destroy()
end)
Can anyone tell me how I could make someone spawn after they press the button?
Just make player max health zero until they click the player button.
Example:
--Server Sided
game.Players.PlayerAdded:Connect(function(player)
player.MaxHealth = 0 --This will repeat kill/prevent the player from spawning
end)
--Client sided
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function() --Something like this, it might error though as I don't think I followed syntax.
player.MaxHealth = 100
end)
Read this article, it has all the information you are asking for. Player | Roblox Creator Documentation, just disable Character auto loading and link the play button to Player:LoadCharacter.
First of All, You Don’t want the Character to Spawn unless they Press the
Button. You Should Put this Inside A Script In ServerScript. And Add a Remote Event in Replicated Storage.
Now You Need to Spawn the Character Once The Button Is Clicked.
You Can Use :LoadCharacter for This.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local PlayButton = script.Parent.Play
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
PlayButton.MouseButton1Click:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
PlayButton:Destroy()
game.ReplicatedStorage.RemoteEvent:FireServer() -- I Added this Line
end)
-- Always use WaitForChild and GetService, especially in local scripts
local Player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local PlayButton = script.Parent:WaitForChild("Play")
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace:WaitForChild("CameraPart").CFrame
PlayButton.MouseButton1Click:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
PlayButton:Destroy()
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer()
end)
Server:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connecg(function(player)
player:LoadCharacter()
local character = player.Character or player.Character:Wait()
character.Humanoid.Died:Connect(function()
player:LoadCharacter()
end)
end)
Try this For the Server →
I Tested this Out on A Baseplate it It Seemed to Work smoothly.
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:Connect(function(Player)
Player:LoadCharacter()
repeat wait() until Player.Character:FindFirstChild("Humanoid") -- Loaded Character Humanoid
Player.Character.Parent = game.ServerStorage -- Store It
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
repeat wait() until game.ServerStorage:FindFirstChild(Player.Character.Name)
game.ServerStorage:FindFirstChild(Player.Character.Name).Parent = game.Workspace
print("LoadedCharacter")
end)
And This for Client
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local PlayButton = script.Parent.Play
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
PlayButton.MouseButton1Click:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
PlayButton:Destroy()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
(I feel it unnecessary to say the Script is the Server and LocalScript the Client…)
Did I format this wrong? Is my understanding of the client-server model incorrect? Please help me understand.