Managing Place Instances in Roblox - roblox

So, apparently Roblox now has a way to Teleport players between places.
That's great, but for the game I have in mind I need to have very fine-grained control over which players are let into which servers (or as Roblox seems to call them, "place instances"). How can I explicitly teleport a player or group of players to a new place instance with no other players in it?

You can find the relevant article on the wiki here
Here is an example code:
local AssetService = Game:GetService(“AssetService”)
local TeleportService = Game:GetService("TeleportService")
local NewPlaceName = "New place #: " .. math.random() * 100
local NewPlaceId = AssetService:CreatePlaceAsync(NewPlaceName , [ID of template] )
for i,Player in ipairs(Game.Players:GetPlayers()) do
TeleportService:Teleport(NewPlaceId , Player)
end
The code will make a new instance from an template with the id [ID of template] and then send all players in the current game to that instance.
You can get more control by using the DataStore (as seen in example)

Try making a Reserve Server. Reserve servers are generated to lock players out and hide the server, players can only join the server when the script you have made teleported them to the place it is running with the code it generated.
https://developer.roblox.com/api-reference/function/TeleportService/ReserveServer

Related

Roblox - creating a multistory maze

I am trying to create a multistory maze. I found it fairly easy to create the first level, then I realized I had no idea how to simply raise this first level up in order to create a second level beneath it.
Also, is there a way to 'fuse' all of these wall parts into one object and then raise this object up?
Edit: Much to my embarrassment, their is a way to fuse objects. The 'Union' tool is what I needed, but had no idea existed. I 'fused' (unioned) the various parts that made up my walls and joined them together into one big part. After that unioning, moving the entire maze upwards became quite easy.
I don't understand your problem but I think that you're making a 3D maze in roblox and you want the first level to go up and the second level to form below the level.
If the maze is NOT procedurally generated AND the maps are built by hand. Then you can make the script detect if the player won, and then raise the first level by either using tween or using loops (I'd recommend tween because loops and linear tweening does the same), and then make an effect that shows it forming (Transparency, parts coming back together, etc..).
I will show you the simplest example. But you can add whatever you want
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.5, Enum.TweenStyle.Linear, Enum.TweenDirection.Out) --Customize it to your liking
local levels = game.LevelStorageParent.LevelFolderOrModelHere:GetChildren()
local pos = workspace.Level1.Position --Change (Not the levels because we are not cloning this)
local levelYRaise = 10 --Put any number or just get bounding box for full raise
ts:Create(workspace.Level1, ti, {Position = Vector3.new(pos.X, pos.Y+levelYRaise, pos.Z):Play()
local newLevel = levels.Level2:Clone()
newLevel.Parent = workspace
newLevel.Pos = workspace.Level1.Position - Vector3.new(0, workspace.Level1.Size.Y, 0)
newLevel.Transparency = 1
ts:Create(newLevel, ti, {Transparency = 0}):Play()
Change the code to your liking and your hierarchy names and parenting

How to make object following player smooth

I use MoveTo for following the position and change the CFrame for rotation but it looks supper jaggy. I think the problem is that the code is on the server-side and not on the client-side since I want other players to be able to see the object following the player
Try using weldConstrain. You can create it by code and connect 2 parts to it. The parts are going to stay at the same relative position from each other. Here is a link for the API reference about the subject: https://developer.roblox.com/en-us/api-reference/class/WeldConstraint
Here is an example code that adds a part at the top of a player's head when it joins the game:
local Players = game:GetService('Players') -- get's the players service
local function OnPlayerAdded(player)
local PlayerCharacter = player.Character
-- waits until the player's character loads
while PlayerCharacter == nil do
wait(1)
PlayerCharacter = player.Character
end
-- Get's the player's model in workspace
local PlayerModel = workspace:WaitForChild(PlayerCharacter.Name)
-- Get's the player's head inside it's model
local PlayerHead = PlayerModel:WaitForChild('Head')
-- Write the path to the part you want to follow the player, bellow
local FollowPartOriginal = workspace:WaitForChild('Part')
-- If you want to clone the part, so more players can be followed by it,
-- don't delete the line below, if you want only 1 part, delete the line below.
local FollowPart = FollowPartOriginal:Clone()
-- set's the part position on top of the player's head, with an offset
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(0,2,0)
FollowPart.Parent = workspace
-- creates a weldconstrain
local WeldConstraint = Instance.new('WeldConstraint')
-- connect's the weld to the player's head and the other part
WeldConstraint.Part0 = PlayerHead
WeldConstraint.Part1 = FollowPart
WeldConstraint.Parent = PlayerHead
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Place this code in a script(not a local script).
If you use the function separately, don't forget to put the player parameter. The parameter needs to contain the player Instance(ex: game.Players.PlayerName)
To change the part position, use the offset in this line of the code:
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(write offset here)
If you want the part the stop following the player, make a script to delete the part, or the weld constrain(child of the player's head)

Animation Script not working in ReplicatedStorager

I have a a Gun model that shows up on my screen using the code from https://www.youtube.com/watch?v=VDYtZxnz7FI&t=25s youtube video. But when I try to add animations to it the animations dont work. What I think is happening is that the script isnt loading in because its in Replicated Storage. I Know this because I tested a simple print command and it worked when the script was in the workspace but not in replicated storage. I cant move the model to the workspace because the code depends on it being in replicated storage. If anyone could help me that would be much abliged. Thank You! Im not new to the Roblox scene but im just starting as a Scripter, Either then a mesh modeler.[Picture of Explorer][1]
Here Is the code that puts the viewmodel on my screen
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local reps = game:GetService("ReplicatedStorage")
local model = reps:WaitForChild("Henry Rifle"):Clone()
for i,v in pairs (model:GetChildren()) do
if v:IsA("BasePart") then
if v ~= model.PrimaryPart then
local weld = Instance.new("Weld")
weld.Part0 = model.PrimaryPart
weld.Part1 = v
weld.C0 = model.PrimaryPart.CFrame:inverse()
weld.C1 = v.CFrame:inverse()
weld.Name = v.Name
weld.Parent = model.PrimaryPart
end
end
end
model.Parent = cam
run.RenderStepped:connect(function()
model:SetPrimaryPartCFrame(cam.CFrame *CFrame.new(0,-1.5,1.5))
end)
Here is the simple code that start the animation when the game starts
(Used for Testing)
local player = game.Players.LocalPlayer
local controller = script.Parent.Humanoid
local inspect = controller:LoadAnimation(script.Parent.Inspect)
inspect.Looped = true
inspect:Play()
I'm pretty sure your script doesn't work because Roblox forces Filtering Enabled now.
Filtering Enabled (FE)
Difference with non FE and FE games
With FE, Changes made by the Client/Roblox Player is sent to the server, but the server will never replicate the changes made by the Client to others Clients in the same game server.
That video was made when FE was still an option. Roblox forces FE now, this is why your script doesn't work.
Only way for Client to replicate with others Clients, You must use Remotes.
Roblox wiki explains better than me FE and Remotes, so check it out: http://roblox.wikia.com/wiki/Replication_filtering

Sending a model through remote functions? ROBLOX

well hello there,
So I'll get right to the point..
Everyone knows that in Roblox you have a ReplicatedStorage (for Client and Server) and a ServerStorage (only for Server).
So I want to store all my assets in ServerStorage .. you know, since exploiters/hackers can't see the ServerStorage if they tried.
However my game has virtual worlds..meaning that the client sees different objects than the other clients at any given time, so I can't just load an object from a server scripts because then everyone will see it.
Heres the question: Can I perhaps set up a remote function that lets the Client invoke the Server, and then the Server returns a model object or its location or something like that? And can I then use the Client to load the model into the player's workspace?
^That way I can securely store my important game assets in the serverstorage
The answer to your question is "Yes, you can!"
First off, you're going to want to create a RemoteFunction in the ReplicatedStorage. Call this RemoteFunction, 'GetModel'
Now, we're going to set up a local script inside of the StarterPack. This local script should have the following code:
local RS = game:GetService("ReplicatedStorage")
local RF = RS:WaitForChild("GetModel")
local model = RF:InvokeServer("ModelName") -- This code can go anywhere you'd like it to go. 'ModelName' is the name of the model you want to get.
print(model.Name) -- This will print the model's name.
Alright, so we've setup our code to invoke the remotefunction. Now, let's make that RemoteFunction do something. We'll create a server script inside of ServerScriptService. Here's the code:
local RS = game:GetService("ReplicatedStorage")
local RF = RS:WaitForChild("GetModel")
RF.OnServerInvoke = function(player, modelName)
local model = game.ServerStorage:FindFirstChild(modelName)
if model == nil then
return nil
else
return model
end
end
Most of this is basic code, and from what you said in the question it seems you understand lua fine. Hope I helped you! :)

Gamecenter Matchmaking - How do I distinguish between player 1 and 2?

I am beginning to write a game using gamecenter matchmaking. Right now, two players can connect to each other, but I am having trouble figuring out how to distinguish between player 1 and 2. For example, I want player 1 to be able to move player 1 and player 2 to be able to move player 2.
The implementation would be specific to your app so it would be hard to answer more specifically, but basically each person's instance of the app could have an object that is "local player" and an object that is "opponent"... Both of them get to move the "local player" in their local instance, and changes to their "player" are obviously mapped to the "opponent" at the other end.
Just do a random number exchance to decide who will be player1 and make the first move.
Generate a random number and store it in a variable.
Send that generated random number to opponent.
Just like this, your opponent sends his own random number to you.
When you receive it, compare with yours.
If yours is greater than his, then you are player1 and he is player2. So you will make the first move.
If yours is lesser than his, then you are player2 and he is player1. So he will make the first move.
If yours and his number are equal (a very rare case) repeat the procedure.
As a reminder, you need to distinguish message types. So use different message type headers. For example: 'R' for random, 'M' for moves.