Raycast weapons

Is there any reason the basic raycast weapons do not work?

local settings = {
	["tooltip"] = "Banana";
	["name"] = "Bananana";
	["dtime"] = .05;
	["cooldown"] = .5;
	["rldtime"] = 1;
	["maxammo"] = 12;
	["damage"] = 100;
	["automatic"] = false;
	["range"] = 1500;
	["reloadwhenout"] = true;
}



db = false
local rld = false
local ammo = settings["maxammo"]
local plr = game.Players.LocalPlayer;
repeat wait() until plr.Character;
local char = plr.Character;
local mouse = plr:GetMouse()
local tool, handle = script.Parent, script.Parent:FindFirstChild("Handle");
local r = game:GetService("RunService")
local hold = false
local enabled = false

tool.ToolTip = settings["tooltip"]

local function reload()
			if ammo <= 31 then
			if rld == false then rld = true
			if db == false then db = true
			tool.Reload:Play()
			tool.Name = "REL."
				wait(settings["rldtime"]/3)
				tool.Name = "REL.."
				wait(settings["rldtime"]/3)
				tool.Name = "REL..."
				wait(settings["rldtime"]/3)
			ammo = settings["maxammo"]
			tool.Name = settings["name"].." ".."["..ammo.."]"
			end
			end
		rld = false
	db = false
	end
end


local function FireRay()
	if enabled == false then return end
	if ammo > 0 then
	if db == false then db = true
tool.Name = settings["name"].." ".."["..ammo.."]"
tool.Shot:Play()
		ammo = ammo - 1
	local ray = Ray.new(handle.Position,(mouse.Hit.p-handle.Position).unit*settings["range"])
		local hit,pos = workspace:FindPartOnRay(ray,char)
		tool.Name = settings["name"].." ".."["..ammo.."]"
		if hit ~= nil then
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid:TakeDamage(settings["damage"])
			end
		end
			local p = Instance.new("Part",workspace)
				p.Anchored = true
					p.CanCollide = false
						p.Name = "Bullet"
							p.BrickColor = BrickColor.new("New Yeller")
								p.FormFactor = "Custom"
									p.TopSurface = "Smooth"
							p.BottomSurface = "Smooth"
						local s = (pos-handle.Position).magnitude
					p.Size = Vector3.new(.2,.2,s)
			p.CFrame = CFrame.new(pos,handle.Position)*CFrame.new(0,0,-s/2)
	coroutine.resume(coroutine.create(function()
		wait(settings["dtime"])
		p:Destroy()
	end))
	end
	end
	wait(settings["cooldown"])
	db = false
	if rld == true then db = true
	end
end

tool.Equipped:connect(function(mouse2)
	if enabled == false then enabled = true
mouse2.Icon = "rbxasset://textures\\GunCursor.png"
if settings["automatic"] == true then
	mouse.Button1Down:connect(function()
		hold = true
			while hold do
				r.RenderStepped:wait()
				FireRay()
				if ammo <= 0 and settings["reloadwhenout"] == true then
					reload()
				end
			end
		end)
			mouse.Button1Up:connect(function()
					hold = false
		end)
else
	mouse.Button1Down:connect(function()
		FireRay()
		if ammo <= 0 and settings["reloadwhenout"] == true then
			reload()
		end
	end)
end
	end
	tool.Unequipped:connect(function()
		if enabled == true then enabled = false
		else
			return
		end
	end)
end)

mouse.KeyDown:connect(function(key)
	if enabled == false then return end
	if key:lower() == "r" then
	reload()
	end
end)

In what way? Always explain what you expected to happen and what actually happened, otherwise there’s no way to know what you’re having trouble with

1 Like

From the looks of the program, this’s handled entirely on the client – you’d want to utilize remote communication, having the client make a request to the server to fire the weapon.

I mean the other players death shows up on the client/players side, but not on the server.

That’s because the program handling the damage’s being dealt on the client and not the server. Like I said in my previous reply…

You want the server to handle the damage, creating the “bullet”, verifying if the shot’s possible, etc. and not the client. The client would send the mouse’s aim position and the server to verify and perform the necessary instructions thereafter.