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

I need help with my gun, It appears to do literally nothing (?)

Hello Developers!

I've made this Raycast gun which depending where you click, a bullet will shoot towards were your mouse Is, the problem Is that even If I use the weapon, It does nothing

Script:

local Tool = script.Parent

Tool.RemoteEvent.OnServerEvent:Connect(function(player,mousePos)
	local Raycastparams = RaycastParams:new()
	Raycastparams.FilterDescendantsInstances = {player.Character}
	Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastResault = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*500, Raycastparams)
	
	if raycastResault then
		local NewInstance = raycastResault.Instance
		local Posistion = NewInstance:FindFirstAncestorOfClass("Part")
		if Posistion then
			local HitMark = Instance.new("Part",game.Workspace)
			game:GetService("Debris"):AddItem(HitMark,2)
			HitMark.Position = Posistion.Position
			HitMark.Anchored = true
			HitMark.Transparency = 0.5
			HitMark.CanCollide = false
			HitMark.Size = Vector3.new(0.838, 1, 1.059)
			local Bullet = Instance.new("Part",game.Workspace)
			game:GetService("Debris"):AddItem(Bullet,5)
			Bullet.Position = Tool.Handle
			Bullet.CFrame = CFrame.new(Bullet.Position, HitMark.Position)
			Bullet.Anchored = true
			Bullet.CanCollide = false
			Bullet.Size = Vector3.new(0.838, 1, 1.059)
			for i=0, 30 do
				Bullet.CFrame = Bullet.CFrame + Vector3.new(Bullet.CFrame.LookVector*5)
				wait()
			end
			game:GetService("Debris"):AddItem(Bullet,0)
		end
	end
end)

1 comment

0

It looks like you posted server-side code. Do you have a LocalScript? What are its contents? More information needed.

1 answer

The direction should be

local direction = (position - origin).Unit * 300

position is the mouse position (Vector3) Origin is the origin where the place the raycast starts (Vector3). .Unit makes the vector compatible for directional raycasting (Vector3). *300 is how many studs you want the raycast to go forward.

Maybe this is what is holding you down. The raycastResult should look like this:

local result = workspace:Raycast(origin,direction,raycastParams)

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