I want to script players into a specific place because they didn’t click play yet and when they do I respawn them into the map
You can just set their cframe to a specified place and remove all movement.
You can load in a player using :LoadCharacter
from a server script. If they are already loaded in, you can do what @NoxhazeI said and set their CFrame
.
Using :LoadCharacter() means that no gui will appear.
okay so, what you could do is something like this
local Players = game:GetService("Players")
local tempPosition = Vector3.new(0,0,0) --this is the position the characters will
-- take before pressing play
local finalPos = Vector3.new(1,1,1) --this is the positions they will be teleported
--to when they press play
Players.PlayerAdded:Connect(function(newPlayer)
newPlayer.CharacterAdded:Connect(function(char)
char:PivotTo(CFrame.new(tempPosition))
end
end)
--then, when they press play, call this line
char:PivotTo(CFrame.new(finalPosition))
If the player’s character loads in on start, you can just move their HumanoidRootPart
to where you want them to start when they press the play button.
If not, you will have to manually place gui into their playerGUI and then use :LoadCharacter
.
Server script (example):
game:GetService("Players").PlayerAdded:Connect(function(plr)
script.GUI:Clone.Parent = plr.PlayerGui -- gui name could be anything, just an example
end)
-- remotefunction placed somewhere both server and client can see, like ReplicatedStorage
event.OnServerEvent:Connect(function(plr)
plr:LoadCharacter()
game.Workspace[plr.Name].HumanoidRootPart.Position = --place you want them to spawn
end)
Local script:
playbutton.Activated:Connect(function()
event:FireServer() -- this should be the same event that the server listens for in OnServerEvent
end)
@NoxhazeI Sorry for the confusion, I thought OP already placed the GUI into the PlayerGui as he spoke about a play button and did not mention GUI not appearing.
add a remoteevent in replicatedstorage named ‘Play’
this should be in one of your localscripts
local playButton = playbuttongoeshere
playButton.MouseButton1Click:Connect(function()
game:GetService("ReplicatedStorage").Play:FireServer()
end)
this should be a serverscript in serverscriptservice
local teleportPart = teleportparthere
local spawnPart = menuparthere
game.ReplicatedStorage.Play.OnServerEvent:Connect(function(player)
player.Character:PivotTo(teleportPart:GetPivot())
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Once(char)
char:PivotTo(spawnPart:GetPivot())
end)
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.