I need to make a wave system for every player - lua

I have a few islands, where players spawn, and I need to make a wave(round like in TD games) system for every player, and, when a player leaves and then joins the game, everything should start from a wave, where the player finished. I guess I know how to save data but I really don't know how to make a separate wave system for every player, I mean, where I have to save the value of the wave number. I'm a total noob in everything so I really don't understand how starter pack changes work and server storage also. So I would be rlly happy if anyone could help with it.
Also, I know that there are module scripts and they may help here, but I don't know how can I use it here.
I have a spawner of enemies and I need to change it for the wave system
local marine = rs.Enemies.OnePiece.Marine2:Clone()
local anim = rs.EnemiesScripts:FindFirstChild("Animation"):Clone()
local move = rs.EnemiesScripts:FindFirstChild("Movement"):Clone()
local hpBar = rs.BillboardUi.HpBar:Clone()
hpBar.Parent = marine
move.Parent = marine
anim.Parent = marine
marine.Parent = workspace.Islands:WaitForChild("1").Bodies:WaitForChild("enemies")
marine.HumanoidRootPart.CFrame = marine.Parent.Parent.Parent:FindFirstChild("enemySpawner").CFrame * CFrame.new(0,10,0) * CFrame.Angles(0,3.2,0)````

Related

Camera won`t focus in a part

I Have a bug, so script that focus camera doesn`t works in my game. But in roblox studio testing mode in works. It is Liocalscript located in StarterPlayerScripts.
That`s my script.
local cam = workspace.Camera
local cameraType = Enum.CameraType.Scriptable
cam.CameraType = cameraType
repeat
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
while wait() do
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = workspace.CameraPart.CFrame
end
I tried making not a LocalScript. Also pasting it in ServerScriptStorage, making it local and not local script.
First off, you will always want to run this locally, since the player is the only person that's going to have a camera in a real Roblox game.
I'm assuming that you want to control the camera of the playing user with as script. If that's true, you should only need to set the CameraType property once. There's no point in using a loop there. Once you set the camera type to Scriptable, you need to set the camera's CFrame to look at the part that you're targeting.
If I had a part in the workspace called "MyPart", then I could set the camera's CFrame to look in front of it. Where you set the CFrame is your choice. One way this can be accompished is setting the position of the camera 4 studs away from the part's LookVector and look at the part.
A pseudocode example of this is shown below:
local part = workspace.MyPart
local cam = workspace.CurrentCamera
-- Set camera type
cam.CameraType = Enum.CameraType.Scriptable
-- Focus camera on part once
cam.CFrame = CFrame.new((part.CFrame + part.LookVector * 4).Position, part.Position)
If the part moved, however, you would have to compensate for that. If you plan on making the camera focus on the part dynamically, you will want to set the camera's CFrame on every frame, which can be done with RunService.RenderStepped.
Considering the fact that you're struggling a bit with the fundamentals of Roblox scripting, you may want to look a bit into Roblox's API reference and doing easier projects for the time being.

Load player character to dummy

I'm pretty new to scripting but I'm trying to make a lobby system. Basically when players join they are assigned to the 4 dummies (so 4 players max). So the dummies look like the players. I'm getting very confused looking at the Roblox documentation followed by little scripting experience experience.
I want to:
First delete any dummys that are already loaded
Assign players to the dummies as they join then remove dummies as they leave
Duplicate the dummies from replicated storage and parent them to the Workspace.
Just looking for some guidance please don't write an entire script as I'm trying to use this as a learning tool.
Hers the code so far and now my head hurts haha
local function characterRig()
for i,player in pairs(game.Players:GetPlayers()) do
local dummy = game.ServerStorage["Dummy"..i]
player.CharacterAutoLoads = false
player.Character = dummy
local playerHumanoid = player.Character.humanoid
playerHumanoid:GetHumanoidDescriptionFromUserId()
dummy.Parent = workspace
end
end
game.Players.PlayerAdded:Connect(characterRig)
game.Players.PlayerRemoving:Connect(characterRig)

How to create a hitbox that lets players through if they have enough money and keeps them out when they don't have enough? - Roblox

Been trying for a while now, not sure how to create a way to block players who don't have enough money to enter a zone and let players through who have enough money if not more.
I have a fully transparent part that i would like to act as the hitbox. I also have leaderstats set up and functioning.
If anyone could help, would be much appreciated :)
This is a great use-case for PhysicsService's CollisionGroups.
You can set up a CollisionGroup where objects in one group do not collide with those in another. It's often used for engine optimizations when a lot of objects simply don't need to check whether they need to collide with others, but you can definitely use them for this as well.
For this case, we'll set the door to be in one collision group, and every player that has unlocked the door will be in another. When they touch the door, it will check how much money they have, and if they have enough it will add each part of their character model into the unlocked group. This will allow their character model to phase right through the door.
So, in order to make this work, I added a Script to the Part that I was using for the door, and I added this code :
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local COST_TO_ENTER = 10 -- update with the actual cost to open the door
local DOOR_GUID = game.HttpService:GenerateGUID()
local LOCKED_DOOR_ID = "LockedDoor" .. DOOR_GUID
local ALLOWED_PLAYERS_ID = "UnlockedPlayers" .. DOOR_GUID
-- find the door that we'll be unlocking
local door = script.Parent
-- create a collision group for the door, and another for players that have unlocked it
PhysicsService:CreateCollisionGroup(LOCKED_DOOR_ID)
PhysicsService:CreateCollisionGroup(ALLOWED_PLAYERS_ID)
-- add the door to the door's collision group
PhysicsService:SetPartCollisionGroup(door, LOCKED_DOOR_ID)
-- make it so that character models in the unlocked group don't collide with the door
PhysicsService:CollisionGroupSetCollidable(LOCKED_DOOR_ID, ALLOWED_PLAYERS_ID, false)
-- listen for when players touch the door to see if we should unlock it
door.Touched:Connect(function(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
if player.leaderstats.Money.Value >= COST_TO_ENTER then
-- if they have enough money, add their character model to the allowed player collision group
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, ALLOWED_PLAYERS_ID)
end
end
-- TODO : update the visuals of the door client-side so that players know that it is unlocked for them
end
end
end)
-- clean up if the door is getting deleted
door.Destroying:Connect(function()
PhysicsService:RemoveCollisionGroup(LOCKED_DOOR_ID)
PhysicsService:RemoveCollisionGroup(ALLOWED_PLAYERS_ID)
end)
This system doesn't persist whether a player has unlocked the door. So if your character dies, they may need to have enough money to get back in again. But it would be fairly simple to add a receipt system that keeps track which players have unlocked it, and re-add character models to the collision group upon respawn.
Not Enough Money
Enough Money
Every time the money changes, you would also change the CanCollide property of the hitbox. For example:
money.Changed:Connect(function()
hitbox.CanCollide = money.Value < 1024
end)
Here, the < operator will return true if the value of money is smaller than 1024, false otherwise. So if the amount of money is small, the block will collide with the player (not letting him/her in), but otherwise it doesn't.
You would do that in the client so that it only applies to that specific client, not all clients.
Protecting it from cheaters isn't necessary in this case, Roblox characters themselves are exploitable. If you're making an anti-cheat, you can make these zones impossible to enter by teleporting the player to their previous position if they enter when they shouldn't be able to.

How to make a player fly to a point in lua roblox?

I want my player to fly at a certain speed to the specified point after running the code, it should not be teleportation, but exactly smooth movement, as in this video - https://youtu.be/_p7HmviCIF8?t=231
For your case here, if you want an exact time for every teleport, you're gonna need to use TweenService.
So you're first going to reference where you're going. Let's say that our point is a CFrame value of an object.
Remember, whenever we want to tp our character, we use CFrames and not Positions.
So first, you're gonna wanna make a TweenInfo, which is basically the parameters of the tween, e.g Time to get to the point, the movement it should have (Linear, Elastic, etc.), etc.
And then you're gonna need a table containing of the property that needs to be changed. In which case we want the CFrame value of the HumanoidRootPart to be the point we set.
Then we're going to make a new tween and have it tween our HumanoidRootPart CFrame to the point CFrame.
local TweenService = game:GetService("TweenService")
local TweeningInfo = TweenInfo.new(
-- The time to get there here
)
local TargetValue = {
CFrame = -- Point CFrame here.
}
local Tween = TweenService:Create(game.Players.LocalPlayer.Character.HumanoidRootPart, TweeningInfo, TargetValue)
Tween:Play()
For your video its just an script for a exploit like synapse x but there are a lot of pastebin or free scripts in toolbox or simply video on that or use the adonis admin on studio and run this in chat :fly me "speed"

How do I use pathfinder to make the NPC chase a player

I already tried looking up multiple solutions in the Roblox developer forums, but I only found some unfinished code or some code that didn't work with mine. The code in this picture makes my rig find the part and chase it until it's there. That works perfectly, but I've been trying to find a way for the rig to chase the nearest player instead. I've heard of magnitude, but I'm not sure how to implement it, I cant even make the rig chase a player in the first place.
First off, .magnitude is the "length of a vector". It is mostly used to find the distance in vector units from pointA to pointB. Hence, the distance from the 2 points would be (pointA.Position-pointB.Position).magnitude.
https://developer.roblox.com/en-us/articles/Magnitude
Now in order to chase the players, you can loop through all of the players and get the one your NPC will chase.
You can use a for loop and loop through game.Players:GetPlayers() then get their character: <v>.Character and then their HumanoidRootPart which has their position. If you wanted to have a range for your NPC or an 'aggro distance', this is where you can implement magnitude. You would first create a variable for your distance. Since we will be dealing with vector units, it should be in length of vectors. For example local aggroDistance = 30. When added to the code, this would mean that it would only track a player if they are within 30 studs. You would then put an if statement saying if (<NPC.HumanoidRootPart.Position-<players hrp position>).magnitude < aggroDistance then. Now you could use Pathfinding Service to move the NPC to the player by using PathfindingService:ComputeAsync(<NPC HumanoidRootPart Position, <player HumanoidRootPart Position>) :ComputeAsync() makes a path from the starting position (the first parameter) to the end position (the second parameter). <NPC Humanoid>:MoveTo(<player HumanoidRootPart Position>) then makes the NPC move to the player. In order to listen out for when the NPC has reached the end of the path it made in :ComputeAsync() you can do <NPC Humanoid>:MoveToFinished:Connect(function()) to run a function after it reached the end, or <NPC Humanoid>:MoveToFinished:Wait() to wait before computing the next path.
Tip: You might also want to check if the player has more than 0 health (if they are alive) so the NPC only moves to players who are alive. You can do this by adding a and <player>.Humanoid.Health > 0 in the if statement where you had your aggroDistance.
Please let me know if you have any questions.
Code Makeup:
aggroDistance variable < optional
while loop
if statement (can contain aggroDistance variable if you have one) and check player health
:ComputeAsync()
:MoveTo()
:MoveToFinished
if statement end
while loop end

Resources