How cam I make a part stick to anything that it touches?

  1. I’m making a grenade and I need it to stick onto what ever it touches. (INCLUDING Terrain!) I’m not sure how to do this. I’ve tried searching and searching… nothing. All I need is a script that makes the part (grenade) stick to whatever it touches first.

Search the forums for ‘sticky bomb’.

Im not so sure about the terrain part but you could use a weld, which gets created, uppon the grenade touches the ground or a part/player. That would be quite easy to implement, else you might need to use raycast.

I’ve tried but I don’t see anything on how to make it stick to terrain or on any part it touches. (player, building, terrain, etc.)

how would I script that though? Like how would I get the other part that it hit?

also for the Terrain part wouldn’t I just have to say the material and then make a weld from the grenade to that material at the grenades current position? Or would I just have to anchor it when it hits another object?

I dont use roblox’s terrain too often, so im unsure, but i dont think welds exactly work with terrain, since you have to add a part0 or a part1. Since terrain is not moving you could anchor the bomb tho, or create an anchored part and weld it to

You could put something like this in a loop

for _, i in pairs(part:GetTouchingParts()) do
    if i:isA("Part") then
        local weld = Instance.new("Weld")
        weld.Part0 = --where ever the basepart/hitbox of the grenade is
        weld.Part1 = i
    end
end

The code may or may not work fully, since im replying on my phone and sometimes Typos may occur

there’s no typos, but the script doesn’t work. I’m not sure how else I can do this but I will try to do the anchor method.

I might try to continue helping in a bit, but i need some sleep

okay ty for helping! goodnight lol.

Using Touched event and creating Welds should work

Touched event DOES fire with terrain so this would also stick to terrain

Example:

local hasHit = false

grenade.Touched:Connect(function(touch) --Touched event fires with Terrain too
	if hasHit == false then -- If the grenade isn't already stuck to something then
		hasHit = true -- Set to stuck

		-- Weld grenade to touched part
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = grenade
		weld.Part1 = touch
		weld.Parent = grenade
	end
end)

ty for helping but unfortunately it didn’t work.

It’s pretty hard to help if you don’t provide me some more details tho lol, any errors? is the part’s “CanTouch” property set to on? is the script inside the part? Maybe providing us with a gif/video would help!

The Cantouch was off but now it works! sorry for not providing enough info. I was away from pc that time and couldn’t remember about the grenade. but other than that tysm!

1 Like

That’s fine, I’m glad it worked at the end! one thing tho… Althought the Touched Event does fire with terrain, I don’t think you can weld a part to the terrain, so you might have to create an invisible anchored part and weld the grande to it if it hits terrain.

1 Like

Or just anchor the grenade if it touches Terrain.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.