I want to create a system where when two cubes touch eachother, it merges into a new type. The problem lies in the touching part. I dont know why it refuses to fire the .Touched event. Here is the part of the code in which the .Touched function is handled:
local function Touch(p: BasePart)
print(p)
if handle.Parent == BlocksFolder then
if p:IsDescendantOf(BlocksFolder) then
Disconnect()
Collide(handle, p)
elseif part.Name == "Glass Shard" and p.Parent and p.Parent:FindFirstChildOfClass("Humanoid") then
print("Glass Shard hit humanoid:", p.Parent.Name)
local Cl = ReplicatedStorage.GlassVFX:Clone()
Cl.Parent = workspace
Cl.CFrame = handle.CFrame -- Position effect at handle
Cl.Break.PlaybackSpeed *= Randomizer:NextNumber(0.9, 1.1) -- Assuming Randomizer defined elsewhere
Cl.Break:Play()
for _, v in Cl:GetDescendants() do
if v:IsA("ParticleEmitter") then
v:Emit(v.Rate)
end
end
task.delay(0.5, function()
if Cl and Cl.Parent then Cl:Destroy() end
end)
Atk(nil, p.Parent:FindFirstChildOfClass("Humanoid"), 10, "Sharp", Vector3.new(0, 5, 0)) -- Assuming Atk function exists
handle:Destroy() -- Destroy the shard tool instance
end
end
end
con = handle.Touched:Connect(Touch)
it doesnt even print anything. Here are the common things that ive already known:
Parts are unanchored
Both parts have CanTouch and CanCollide on
The script is running in server side
the connection is still connected, i ran a delay function that prints it’s connection state and all of it returns true after 10 seconds
Both parts are of Part class
i tried forcibly jamming one into another and the Touched function still isnt firing
somehow the Touched function still works in the split second as the game loads, which also consequently makes the delay function printing false
i tried removing everything except the print function in Touch and it still doesnt print out anything
i made my own .Touched connection in the command bar as i was playtesting in server side, and it still doesnt print anything
tried switching the folder into a model, still doesnt work
tried switching between massless of both objects, doesnt work
tried testing everything both in studio and on roblox
tried letting roblox handle network ownership and setting network ownership to nil, neither works
well, in the game i click a part, the server handles it by making the tool the parent of the handle, then parents the tool into the character, and when dropped it reverses this process. When you drop, the tool is pivoted to the mouse position. I tried both methods of pivotting to the desired cube, and above the desired cube, but neither works. Though, if two cubes are already touching, and i rejoin, then they merge into a new cube.
heres a video of the bug in action, as you can see they dont seem to touch at all, or atleast dont fire the touched function, because if they do, it wouldve already ran the Collide() function which turned it into something else.
PS: mind the other bugs, i just recently changed ownership to my group so the animation broke
Since your touched event isn’t even firing, I would have to assume you’re dropping the tool within a LocalScript on the client. That doesn’t replicate to the server, so it’s still in your backpack. Try switching to the server side after you perform a drop to see if it actually happens
so the dropping is actually handled on server side, but it still doesnt fire the touched event. By the way, ignore the bug that when i drop a cube it phases through other cubes, ive already fixed that now and its unrelated to the touched event not firing (its just me forgetting to set collision group)
You should open the RBXL place I sent you and try to find the difference between mine and yours, because I structured it as similarly as possible and got it working
ive found that the problem lies not in the touched event but the game itself, because i had ran in server side, created two parts, and made a touched connection, and it only registers touches for a few moments before completely stop firing the connection. But that means i would need to find the factor in the game settings or stuff that’s been causing this, and I have no clue
I can directly tell you. That happens because physics parts ‘fall asleep’ when they haven’t been updated in a while. According to an old thread, pushing the sleeping block (the already existing one) into the ground softly should wake it up with little chance for movement, since it would already be on top of the ground
Although, you can just use a timed connection which uses GetTouchingParts or GetPartsInPart to determine if anything should be fused, instead of relying on Touched. Then you wouldnt have to worry about sleeping parts