Paintball shooting script - Broken

Hi there!

So I’m making a remake/rebuild of an old paintball game, and I found a good model of a paintball gun that still works.

Now everything seems to be going well… except that it keeps shooting to my right side no matter where I’m facing. I’m not sure how to make it just shooting ahead of them (maybe not following their mouse, but mostly only stay in one line at best?)

Also, oddly it also painted some of the blocks (which I didn’t want it to do that, I just want it to only ‘paint’ the players if they get shot by another player’s paintballs).

I tried looking up how to fix this problem, but no lucks.

Here is the script:
Tool = script.Parent

colors = {23}

function fire(v)

	Tool.Handle.Fire:play()
	

	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)

	local missile = Instance.new("Part")

        

	local spawnPos = vCharacter.PrimaryPart.Position
	


	spawnPos  = spawnPos + (v * 8)

	missile.Position = spawnPos
	missile.Size = Vector3.new(1,1,1)
	missile.Velocity = v * 100
	missile.BrickColor = BrickColor.new(colors[math.random(1, #colors)])
	missile.Shape = 0
	missile.BottomSurface = 0
	missile.TopSurface = 0
	missile.Name = "Paintball"
	missile.Elasticity = 0
	missile.Reflectance = 0
	missile.Friction = .9

	local force = Instance.new("BodyForce")
	force.force = Vector3.new(0,90 * missile:GetMass(),0)
	force.Parent = missile
	
	Tool.BrickCleanup:clone().Parent = missile

	local new_script = script.Parent.Paintball:clone()
	new_script.Disabled = false
	new_script.Parent = missile

	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = vPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = missile
	


	missile.Parent = game.Workspace

end



Tool.Enabled = true
function onActivated()

	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return 
	end

	local targetPos = humanoid.TargetPoint
	local lookAt = (targetPos - character.Head.Position).unit

	fire(lookAt)

	wait(.5)

	Tool.Enabled = true
end


script.Parent.Activated:connect(onActivated)
2 Likes

I have no real solution to this, however, tools like this paintball gun could be broken because Roblox unfortunately doesn’t support them anymore. Example like Roblox skateboards and how Roblox broke them. If there is no solution then the best way is just to make your own paintball gun.

You could try changing the direction of the force to either force.force = Vector3.new(90 * missile:GetMass(),0,0) or force.force = Vector3.new(0,0,90 * missile:GetMass()).

Yeah as @LukeWasAlreadyTaken mentioned the issue is due to the FE filtering update particularly this property concerned with the targeting portion of the script.

This property is a client only property and assuming the script is a server script this target point will only be (0,0,0).

To fix this you have to find a way to transmit where the mouse is pointing perhaps via mouse.Hit or UserInput services in a local script then send it over to this server script via a client to server remote event.

2 Likes

I tried the first one, it just gave the same result, altho it now kinda shoot more straight (but still stuck to the same side from where I was shooting before).

The second doesn’t seem to work at all.

Perhaps these little snippets from my gun code will show what I eventually ended up doing…

== LocalScript (Client Script)

ClientControl = Remotes:WaitForChild("ClientControl")

function OnClientInvoke(mode, value)
	if mode == "MouseData" then
		return {Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target}
	end
end
ClientControl.OnClientInvoke = OnClientInvoke

== Script (Server Script)

function onActivated()
	if enabled then
		enabled = false
		local MouseData = InvokeClient("MouseData")
		if Tool.Parent and Tool.Parent:FindFirstChild("Humanoid") and Tool.Parent:FindFirstChild("Head") and MouseData and MouseData.Position then
			local character = Tool.Parent
			local humanoid = character:FindFirstChild("Humanoid")
			local head = character:FindFirstChild("Head")
			local targetPos = MouseData.Position --humanoid.TargetPoint
			--print(targetPos)
			local lookAt = (targetPos - head.Position).unit

			gunUp()
			fire(lookAt)
			wait(0.1)
			gunOut()
			wait(reloadRate)

			reloadCount = reloadCount + 1
			if reloadCount > 3 then
				Tool.Handle.Reload:Play()
				reloader()
				reloadCount = 0
			end
		end
		enabled = true
	end
end

Since nobody here figured it out, I’ll leave this here: Fixed ClassicPaintballGun - Roblox

As for the bullets painting the objects instead of only players, its an intended behaviour. If you wish to remove it, add a check to the hit script that handles colouring parts to see if the hit.Parent has a humanoid.

Also, read this please: The enabling of FE caused another issue that is only apparent once you attempt to use the gun in normal gameplay. The projectiles are now purely handled by the server and not by the player as they once were when paintball guns were made in 2007. This means that the projectiles are very unsmooth and highly prone to server lag and travelling speed isues. You are highly recommended to make the projectiles localsided to prevent this, through the use of a localscript that creates the projectiles and uses a FireAllClients to show the players the projectile.

Not sure if anyone is still here at this point however in the future, don’t use :InvokeClient because the client can cause serious problems with the server listed here: Remote Events and Functions | Roblox Creator Documentation.

1 Like

Wasn’t really my code, but code from a Roblox gear, however, you are correct, never trust the client will be there or return a value.

So, good advice, thanks for posting.