These scripts aren’t working and there are no errors in the output. Supposed to inflict damage and play an animation, (its a tool). Both scripts are locate inside the tool, one being client and the other being server.
The client is supposed to fire a signal to the server script. I honestly don’t know if it works lol.
Edit: Im actually getting an error message now, cant index nil with waitforchild on server script
Client script:
local fist = script.Parent.Parent
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local server = game.ReplicatedStorage
local Hit = server.Punch
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8194480087"
Puunch = humanoid:LoadAnimation(animation)
function onActivation()
fist.Handle.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local humanoid1 = hit.Parent:FindFirstChild('Humanoid')
local PlayerWhoGotHit = game.Players:GetPlayerFromCharacter(hit.Parent)
Hit:FireServer(PlayerWhoGotHit)
Hit:FireServer(Puunch)
end
end)
--Ignore this part of the code, it inst implemented in the server script
fist.Handle.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Window') then
local window1 = hit.Parent:FindFirstChild('Window')
local parts = {
window1:FindFirstChild("Weld 1"),
window1:FindFirstChild("Weld 2"),
window1:FindFirstChild("Weld 3"),
window1:FindFirstChild("Weld 4"),
window1:FindFirstChild("Weld 5"),
window1:FindFirstChild("Weld 6"),
}
Hit:FireServer(parts)
end
end)
end
--end of code not being used
fist.Activated:Connect(onActivation)
Server script:
local storage = game.ReplicatedStorage
local punch = storage.Punch
local function onActivation(PlayerWhoGotHit, Puunch)
PlayerWhoGotHit:WaitForChild('Humanoid'):TakeDamage(2)
Puunch:Play()
end
punch.OnServerEvent:Connect(onActivation)
You said it doesn’t produce errors, but can you narrow down what’s going on for us? Does the event get fired properly, or does the code fail to fire the event and have the event take place on the server?
A couple of things that may be affecting the code:
If you intend the event to fire only once with both arguments, put them together in a tuple. Hit:FireServer(PlayerWhoGotHit, Puunch)
The first argument of OnServerEvent is always the player who fired the event, so you’ll need to add another variable at the beginning. local function onActivation(Player1, PlayerWhoGotHit, Puunch)
Since it’s a default argument of OnServerEvent, you won’t need to add Player1 to the arguments in the :FireServer() call if that’s what you’re wondering. Not much else about this argument (such as what you call it) really matters if you don’t need to use it; it’s only accounted for at the beginning of OnServerEvent so that one of the variables you actually sent over doesn’t get defined as the sender of the event instead.
I’m assuming this is the line that’s giving you the error if it’s in the server script:
This means that PlayerWhoGotHit is nil. If you’re hitting an NPC, this is probably why the script is erroring since an NPC doesn’t have a corresponding player.
I’ll also point out that you’re trying to find a humanoid inside a player object instead of the character model (this isn’t what’s causing the error, but it will need to be fixed). To fix this problem and make the code work with NPCs, it may be a better idea to send humanoid1 to the server instead of PlayerWhoGotHit since you’ve already defined it and checked that it exists in the client script.
Client: Hit:FireServer(humanoid1, Puunch)
Server:
local function onActivation(Player1, humanoid1, Puunch)
humanoid1:TakeDamage(2)
Puunch:Play()
end
If the player has a forcefield, it is because of that if you are using Humanoid:TakeDamage. Just do Humanoid.Health = Humanoid.Health - (how much you want to remove)
An issue would be that you would need to search for the humanoid in the target’s character right now it’s searching for it in their player, which could be fixed by either doing PlayerWhoGotHit.Character:WaitForChild('Humanoid'):TakeDamage(2)
(instead of PlayerWhoGotHit:WaitForChild('Humanoid'):TakeDamage(2))
or Hit:FireServer(hit.Parent)
(instead of Hit:FireServer(PlayerWhoGotHit))