What's Wrong With My Gun?

Hello developers! I was searching around for help on a gun and Ki1l3rBanana gave me a small tutorial on how to create a Ray Casting Gun. I followed the directions to the point. (As for as I know of.) But when I finished, it didn’t seem to work. Would you mind helping me figure out what I did wrong?

I have 2 scripts that I was told to put in. One was a LocalScript called Player and anouther was a ServerScript called Server. Both of these scripts are inside of a tool called Fifle. There is also a RemoteEvent called PewPew.

The tool and it's children

This one is the LocalScript, called Player:

local Gun = script.Parent
local PEWPEW = Gun:WaitForChild('PewPew')


local players = game:GetService('Players')
local localPlayer = players.LocalPlayer
local Mouse = localPlayer:GetMouse()

function callserver()
	PEWPEW:FireServer(Mouse.Hit.Position)
end


Gun.Activated:Connect(callserver)

This one is the ServerScript, called Server:

local Gun = script.Parent
local muzzle = Gun:WaitForChild('Muzle')
local pewpew = Gun:WaitForChild("PewPew")

local Workspace = game:GetService("Workspace")
local ServerStorage = game:GetService("ServerStorage")

pewpew.OnServerEvent:Connect(function(plaer,position)
	
	local origin = muzzle.Position
	local direction = (position - origin).Unit*360
	local result = Workspace:Raycast(origin,direction)
	
	local HIT = result and result.Position or origin + direction
	local distance = (origin - HIT).Magnitude
	
	local CloneBullet = ServerStorage.Bullet:Clone()
	
	CloneBullet.Size = Vector3.new(.1,.1,distance)
	CloneBullet.CFrame = CFrame.new(origin,HIT)=CFrame.new(0,0-distance/2)
	CloneBullet.Parent = Workspace
	
	if result then
		local part = result.Instance
		local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild:("Humanoid")
		
		if humanoid then
			humanoid:TakeDamage(25)
			
			
		end else
		return
	end
	
	wait(.25)
	CloneBullet:Destroy()
	
end)

That is all. If anyone can help me out I would really appreciate it.

2 Likes

Did you check output because this obviously wouldn’t pass

CFrame.new(origin,HIT)=CFrame.new(0,0-distance/2)
1 Like

I did, and nothing came out. Let me try changing this.

What should I change it to instead?

Probably

CFrame.new(origin,HIT)*CFrame.new(0,0-distance/2)
1 Like

Ok, now that I fixed that, I am getting an error when I click, so I think it fixed something.

1 Like

Ok, now it says the Bullet is not a valid member of ServerStorage. Would you mind looking over the original code to see if I messed up on anything. Also Bullet is not definded in the script, but it works for him somehow.

There’s no bullet in ServerStorage basically.

Yeah but shouldnt it be coded in to ServerStroage? In the tutorial he doesnt have a bullet in serverstorage, but it seems to work. This is so confusing lol

image
They show it in the video lol

Im an idiot, jesus crist lol how did I miss that

1 Like