I’m making a mining game where unanchored ore blocks spawn around an area, and often they get stacked up. The problem is, when mining a block from a stack, the blocks above it get stuck in the air until something touches them. I’m fairly certain this isn’t an issue with my code, since a lot of it is reused from an older game of mine which didn’t have this issue, but I will provide it if needed. I tried to upload a video, to no avail, so here’s an image of my problem instead. Doesn’t show it quite as well, but it should be good enough.
doesn’t this belong in the https://devforum.roblox.com/c/help-and-feedback/building-support building support category?
if this isn’t related to code.
and is to building
Just looked through that category, it might fit in there, but I’m not sure. I definitely could’ve worded this better, but this is about models in a stack being destroyed, which is related to code, and how the other models react, which is related to physics. I see much more threads about visuals there than physics. But, then again, I’m new to posting on here, so there’s a good chance I’m wrong. I’m just hoping for someone who knows what’s going on here and how to fix it, because I’m utterly clueless. This has never happened to me before, and I’m not sure why it’s happening now.
Is your part anchored? or Did U Build it or make it instance? or maybe theres something wrong with your code?
Can you please provide us your code and the directories so we can assist you better?
then change your code, where you create the new instance , as you said they spawn themselves in the minigame, set part.Anchored=false
and divide the model into two section, with the model containing all ore
by divide I mean upper parts and lower parts.Set the upper ones to anchored=false
and lower to true
and when the parts from the upper section reach a y of lets say 30, then anchored =true (part.position)
If this didn’t help you then please provide your code so we can edit it for you and tell you what’s wrong.
This Has Something To Do With Physics right? but if u set it to false then they would fall but you can move though
Here’s a shortened version of the code I used to handle the destruction of the models. It’s triggered by a RemoteEvent in ReplicatedStorage. hit
is the ore model (one of the blocks being stacked), mainpart
is the PrimaryPart of said model, and Health
is an IntValue inside the model.
if tool.Enabled and (plr.Character.HumanoidRootPart.Position-mainpart.Position).magnitude <= range then
hit.Health.Value = hit.Health.Value - damage
if hit.Health.Value <= 0 then hit:Destroy() end
end
It depends , after some insight on the situation based on a specific scenario we could analyze what’s wrong but I think it’s got something to do with his code
Please provide the full code so we can look at all the variables etc.
Please provide the code for onserverevent wherever you’ve kept it and all scripts involved in this.
edit= if you’re trying to destroy the part on click then use a clickdetector for it.
u did add the part what you are going to touch u should add that part also in the script what are you reffering too?
did u add the toolName if hit.Parent == “YourTool Name” then – sample
– ur code
in your block part?
Here’s the full code for onserverevent. It’s fired from a LocalScript inside a pickaxe tool.
event.OnServerEvent:Connect(function(plr, hit)
local tool = plr.Character:FindFirstChildOfClass("Tool")
if not tool:FindFirstChild("MiningTool") or not tool:FindFirstChild("Stats") then return end
local level = tool.Stats:FindFirstChild("Level")
if level.Value < hit.Level.Value then return end
local cooldown = tool.Stats:FindFirstChild("Cooldown").Value
local damage = tool.Stats:FindFirstChild("Damage").Value
local range = tool.Stats:FindFirstChild("Range").Value
local mainpart = hit:IsA("BasePart") and hit or hit:IsA("Model") and hit.PrimaryPart
if tool.Enabled and (plr.Character.HumanoidRootPart.Position-mainpart.Position).magnitude <= range then
tool.Enabled = false
hit.Health.Value = hit.Health.Value - damage
event:FireAllClients(hit)
if hit.Health.Value <= 0 then hit:Destroy() end
wait(cooldown)
tool.Enabled = true
end
end)
If you’re curious about the event being fired on the client, it’s because of a purely visual clientside effect whenever the block is damaged, the issue was happening before I added it. As for the script checking if hit is a model or a basepart, keep in mind that so far hit can only be a model. I just have that bit in there so that potential changes down the line don’t completely break the script.
Not sure how helpful this will be, but here’s a visual in case it’s needed.
why not just use click event?
If you’re referring to a clickdetector, you can’t use those with a tool equipped. The pickaxe tool is how you mine.
its not a click detector its a tool.Activated Event.
Ah, okay. tool.Activated is being used, in the localscript.
tool.Activated:Connect(function()
local hit = mouse.Target
if hit then
if hit.Parent:FindFirstChild("Ore") then target.Value = hit.Parent elseif hit:FindFirstChild("Ore") then target.Value = hit end
end
end)
target.Changed:Connect(function()
if target.Value ~= nil then
local currtarget = target.Value
while true do
repeat wait() until tool.Enabled == true and attacking == false
if target.Value ~= currtarget or not target.Value or not target.Value.Parent or not currtarget or not currtarget.Parent then return end
attacking = true
swing:Play()
swing:AdjustSpeed(speed)
wait((swing.Length/speed) + cooldown)
attacking = false
end
end
end)
swing:GetMarkerReachedSignal("Hit"):Connect(function()
if target.Value and target.Value.Parent ~= nil and target.Value:FindFirstChild("Ore") then
game.ReplicatedStorage.DamageOre:FireServer(target.Value)
end
end)
swing
is an animationtrack.
yes it is used for clicking if u have tried it out
Use Destroy() instead than damage or if u have damage then do UrEvent then simply use destroy
Assuming you’re sure that the blocks are unanchored then I suspect it could be a bug where the parts aren’t being woken from physics sleep (basically the physics system stops calculating for parts that aren’t moving and should start calculating the physics again when the forces acting on the parts change)
Could you add the following code before and after you call destroy
print(game.Workspace:GetNumAwakeParts())
and report what values it prints
if it gives the same value both times then the number of active physics objects isn’t changing which would make me think its not waking the stacked parts when it should
0, aaand… 0. Yikes. How should I go about waking them up? Playing loud music isn’t helping