im making a pretty basic gun using raycasting. the only problem i have so far is the mouse not being defined. it works in test mode, but not in a local server. Localscript:
local gun = script.Parent
local plr = game.Players.LocalPlayer
gun.Activated:connect(function()
local mouse = plr:GetMouse()
gun.FireEvent:FireServer(mouse)
end)
Serverscript:
local gun = script.Parent
local bodyParts = {"Leg", "Arm", "Torso", "Head"}
local dmg = {20, 20, 30, 50}
gun.FireEvent.OnServerEvent:connect(function(plr, mouse)
print("fire")
print("Mouse pressed!")
local ray = Ray.new(gun.Handle.CFrame.p, (mouse.Hit.p - gun.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
for i = 1,4 do
if string.find(part.Name, bodyParts[i]) then
print(i)
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(dmg[i])
end
end
end
end
print(part)
print(position)
end)

3 comments
mouse is to be called localscript only, and on line 4 it's Connect not connect. that is another error
what are you talking about? connect works just fine. both Connect and connect work.
connect is depreciated but to my knowledge will still work (use Connect), are you putting an event inside of the tool? And the script is replicating with each tool as well? To me that doesn't seem like a good idea