What I’m trying to achieve is the Bed Wars’ forge system. In Hypixel Bed Wars, iron and gold drops down from the ceiling on a platform. The iron and gold can be picked up and acts like a currency. (If you don’t play or know what Bed Wars is here is a video depicting of what I’m trying to achieve)
The issue is that I have no idea how to implement this without creating tons of lag by doing so. I also have no idea how I am supposed to try to make it so people can pick it up. I would have to run Instance.new() over and over again while parenting scripts that would allow it to be picked up (and I worry that’s gonna put too much stress on the client/server).
If anyone has any knowledge about stuff like this, let me know, because I am kind of confused on how to do this.
Instead of creating the currency from scratch, create them beforehand and place them in a storage container like ServerStorage, and it shouldn’t stress the server, and to make it be able to be picked up you can make it a tool
local Money = game:GetService("ServerStorage"):WaitForChild("Money")
while true do
local NewMoney = Money:Clone()
NewMoney.Parent = workspace
delay(3,function())
NewMoney:Destroy()
end)
end
This is just a snippet of code I came up with in a few seconds. I just created a loop and just cloned the “Money” object in the ServerStorage and parented it with it being destroyed after 3 seconds. Is this how I should do it or is it not feasible?
DebrisService does actually let you wait a certain amount of time before removing it. Now why should you use it instead? It doesn’t yield the current thread, does not require a new thread and it won’t error if the object is already destroyed.
You can calculate the Magnitude between the Part and the Player to determine whether or not it should be picked up. Though this will cause lag if run when not necessary.
Decide when the magnitude calculation loop should be run by determining when they enter a Region3 near the forge using FindPartsInRegion3.
The way Minecraft handles this is by merging dropped items when they’re too close.
Your money would have two NumberValues. One would be how much money the drop is worth (could just be an IntValue if you want) and the second would be the output of math.random(). When two of these objects collide, a script would determine which part will be destroyed via the random number and the first NumberValue would be incremented based on the to-be-destroyed one’s value.
--Script inside of Money part
--Make the random value
local randomValue = instance.New("NumberValue")
randomValue.Value = math.random()
randomValue.Name = "randomValue"
randomValue.Parent = script.Parent
--Make a IntValue/NumberValue (should be already in studio)
--[[
local value = Instance.new("IntValue")
value.Value = 1
value.Name = "Worth"
value.Parent = script.Parent
]]
script.Parent.Touched:connect(function(part)
--Do some test to see if this is another money part
if part.Name == "Money" then
while randomValue.Value == part.randomValue.Value do --just in case
randomValue.Value = math.random()
wait()
end
if randomValue.Value > part.randomValue.Value then
script.Parent.Worth.Value = script.Parent.Worth.Value + part.Worth.Value
part:Destory()
end
end
end)
remind me to always use notepad++ when writning forum code again
I am actually working on a bed wars game, what i did is when an ore spawns and an ore of the same type is nearby, it deletes that ore and basically increases the value so it acts like a stack