Hello. I was trying to build and code a gun. Here's the code.
Local script
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local shoot = game:GetService("ReplicatedStorage"):WaitForChild("Sparo")
local tool = script.Parent
local hole = script.Parent:WaitForChild("Buco")
tool.Equipped:connect(function()
mouse.Button1Down:connect(function()
local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p)* 500)
local hit, position = workspace:FindPartOnRay(ray, player.Character)
if hit then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
shoot:FireServer(hit, humanoid)
end
end)
end)
Server script
local shoot = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local damage = game.StarterPack.Tool.Configuration.Danno.Value
shoot.OnServerEvent:Connect(function(hit, humanoid)
if hit.Name == "Head" then
print("Headshot")
humanoid:TakeDamage(damage * 2)
else
print("Hit")
humanoid:TakeDamage(damage)
end
end)
The output
Hit
12:03:46.469 - TakeDamage is not a valid member of Part
I can't get it to detect headshots and deal damage.
I tryied to run all the code on a local script and it worked fine. But when I try to use remote events the arguments start working in a weird way. I'm still learning and I would appreciate an explanation of the arguments. Any solution to this?
Thanks in advance.

1 comment
Thanks for the explanation.