Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Raycast somehome avoids the player? How can I fix this?

Whenever I try to shoot at an object, it someone avoids it, otherwise it's fine. Here's the code.

Player = game:GetService("Players").LocalPlayer
Mouse = Player:GetMouse()
Gun = script.Parent

Equip = false



Gun.Unequipped:connect(function()
	Equip = false
	print("Not using pistol")
end)

Gun.Equipped:connect(function()
	Mouse.Icon = "http://www.roblox.com/asset/?id=79658449"
	Equip = true
	print("Using pistols")
	
	
end)




Gun.Activated:connect(function()
	if Equip == true then
		
		--Raycasting
		local BulletRayMatrix = Ray.new(Gun.Handle.CFrame.p, (Mouse.Hit.p).unit*500)
		local part, position = workspace:FindPartOnRay(BulletRayMatrix, Player.Character, false, true) --Part, object that was hit
		
		local Bullet = Instance.new("Part", workspace)
		Bullet.BrickColor = BrickColor.new("Really yellow")
		Bullet.Material = "Neon"
		Bullet.Transparency = 0.5
		Bullet.Anchored = true
		Bullet.Locked = true
		Bullet.CanCollide = false
		
		
		
		local Distance = (Gun.Handle.CFrame.p - position).Magnitude
		Bullet.Size = Vector3.new(0.3, 0.3, Distance)
		Bullet.CFrame = CFrame.new(Gun.Handle.CFrame.p, position) * CFrame.new(0, 0, -Distance / 2)
		
		--Damage
		Bullet.Touched:connect(function(hit)
			local hum = hit.Parent:FindFirstChild("Humanoid")
			if hum ~= nil and hit.Parent.Name ~= Player.Name then
				
			end
		end)
		--
		game.Debris:AddItem(Bullet, 0.2)
		
		
		--Raycasting
		print("shooting")
	else
		return;
		
	end
end)

Any soloutions for this? It's like when I shoot at it it shoots over the object I want to shoot at :(!

1 answer

For the player it could be because mouse has a targetFilter property wich is default set to the character. try adding mouse.TargetFilter = nil and see if that fixes it for the player part.

There's not enough information to give a decent/broad answer

1 comment

0

When firing at nothing, sky or just infront of nothing it shoots normal and casts to where I want it. But when I fire at things that has humanoids it basically avoids it, it shoots above or in the side of it.

This discussion is preserved as it was. New answers, comments, and votes are closed.