Trying to make an injection gun like in Ro-Bio

I wanted to make an injection gun like in ro bio but I dont know how to make the needle move outward when you click it . I think it might have someone to do with Lookvector or something but can someone tell me how to do this without an animation or anything?

This can steer you in the right direction

You can actually get the exact model used in Ro-Bio, as much of it is open-source (or leaked… I can’t remember which one).

In this case, I don’t believe that the needle gun is using the CFrame of the needle part, as over time floating-point errors could lead to misalignment of the needle. I think an easier way to do this would be to mess around with Attachments and Constraints. In this case I think the easiest method would be to use a Weld and then tweening the JointInstance.C1 offset value of the weld. This would be easiest as the C1 value is already in object space.

EDIT:
Alright, I decided to look around and found the models of the needle gun and the collector. You can use them if you want, or use them as an example to base what you’re creating off of. You can check them out below:
https://www.roblox.com/library/5223059414/Ro-Bio-Needle-Guns

I decided to look at how they work, and it turns out my speculation was correct. It works by tweening the C1 property of a Weld. I’ve added the relevant parts of the code below:

Code

I did edit some variable names for clarity and remove unnecessary whitespace, but everything else is unedited.

Here is the function they made for creating and playing tweens:

local function tween(tweenObject,tweenProperties,speed)
	local tweenService = game:GetService("TweenService")
	
	local tweenInformation = TweenInfo.new(
		speed, -- Length
		Enum.EasingStyle.Elastic, -- Easing style of the TweenInfo
		Enum.EasingDirection.Out, -- Easing direction of the TweenInfo
		0, -- Number of times the tween will repeat
		false, -- Should the tween repeat?
		0.1 -- Delay between each tween
	)
	
	tweenService:Create(tweenObject,tweenInformation,tweenProperties):Play() -- Creates and plays the tween
end

And here is how said function was used:

local tool = script.Parent

local both = tool.Needle

local needle = both.metal
local weld = needle.Weld

local usable = true
local can = true

-- Other code

tool.Activated:Connect(function()
	if usable then
		if can then
			can = false
			needle.Sound:Play()
			
			tween(weld,{C1 = weld.C1 * CFrame.new(2,0,0.2)},0.5)
			task.wait(0.7)
			tween(weld,{C1 = weld.C1 * CFrame.new(-2,0,-0.2)},0.5)
			task.wait(1)
			
			can = true
		end
	end
end)

If you decide to create your own however, I would only try distributing the work between the client and the server. Use a WeldConstraint for welding any two parts that don’t need to be manipulated. Also, it’d be easier to do a single raycast on the server to detect if it hits something instead of using the Touched event.

2 Likes

Ok thank you for the help. I will try that out.

I edited my answer with additional information.

Thanks
I will have a look at it

I have always been confused by C1 and C0 , like what exactly are they and what do they do , english terms would be nice if possible.

As far as I know, the C0 property is the offset point for the Part0 and the C1 the offset point for the Part1. I could be wrong though.

It’s called pain.

Jokes aside, it uses cframes. I choke when I say that word as it took me a while to master, but im pretty good at them now. CFrames are made out of position and rotation.
I would use C0 and TweenService to tween the C0 to get animations.