I’m trying to make a function which passes a player’s character if they have been hit by the client’s knife. The remote event fires with two parameters, damage (irrelevant here) and hit. Hit should be a limb of the player’s character which was hit. Problem is, on the server it thinks hit is my player object (in game.Players), not the person who I hit with the knife’s limb.
Client code:
function newBullet()
if WeaponData.WeaponType == "Melee" then
if shooting == false then
shooting = true
local muzzle = WeaponInHand:WaitForChild('Muzzle')
local damage = 100
recoilcf = WeaponData.ShootCFrame
muzzle:WaitForChild("Fire"):Play()
local blade = WeaponInHand.Handle
blade.Touched:Connect(function(hit)
if shooting == true then
if hit.Parent:WaitForChild("Humanoid") then
if hit.Parent ~= plr.Character then
print(hit)
Events.Stab:FireServer(damage,hit)
print('fired')
elseif hit.Parent == plr.Character then
print('lol u hit urself idot')
end
end
end
end)
wait(0.2)
shooting = false
wait(60/WeaponData.ShootRate)
end
end
end
Server code:
local RepStor = game.ReplicatedStorage
local Events = RepStor:WaitForChild("Events")
local function DamageStab(hit,damage)
print(damage)
print(hit) -- this gives my player's name, not the person who i hit!!
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent.Humanoid
print('humanoid found and variable')
if humanoid.Health > 0 then -- if enemey is alive
humanoid:TakeDamage(damage)
print('taking damage')
end
elseif hit.Parent.Humanoid == nil then
print('humanoid nil')
end
end
Events:WaitForChild("Stab").OnServerEvent:Connect(DamageStab)