What do you want to achieve? Keep it simple and clear!
I want it so that when a player hits another player that is smaller, the smaller player dies and the bigger one lives.
What is the issue? Include screenshots / videos if possible!
Everything including the punch, and punch animation works, but when I compare the two players leaderstats it just doesn’t work.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have been picking at this issue for a few days and tried looking for people with similar problems but cant find the solution.
Here is my code.
game.ReplicatedStorage.Remotes.Punch.OnServerEvent:Connect(function(player,damage)
for i,target in pairs(game.Workspace:GetDescendants() ) do
if target:IsA("Humanoid") and target.Parent.Name ~= player.Name then
if (target.Parent.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 8 then
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = player.Character.Humanoid
local Dude = target.Parent.Parent
local Humanoid = Dude:FindFirstChild("Humanoid")
local leaderstats = player:FindFirstChild("leaderstats").Size.Value
local EnemyLeaderstats = Dude:FindFirstChild("leaderstats").Size.Value
if Humanoid and EnemyLeaderstats < leaderstats then
Dude.Health = 0
elseif Humanoid and EnemyLeaderstats > leaderstats then
player.Health = 0
end
wait(1)
end
end
end
end)
Might be a little messed up because I just copy and pasted it here and it doesn’t really fit the page.
Im not getting any kind of errors, but I will fix the player.health and see what happens. Edit: I am getting one error, it says " Script ‘ServerScriptService.Script’, Line 15 " So I think it might be a problem with my variables, but I still don’t really know how to fix them, I am fairly new at scripting.
Ok, one more step away, I used your plrService (thanks btw) and edited the script in a few ways, first off, I had two variables with the same name (Fixed) but the final step would now just be dealing the damage, since Dude is now a variable for the Player and not the humanoid, I cant deal damage to the “enemy” using that variable. How would a get the enemy’s humanoid? (I hope all that made sense)
I have a questions.
Why do you set player health to 0, when there is a damage variable in the event function?
Although I don’t know what is the goal you’re trying to reach, I think this would make more sense.
local distance = 8
game.ReplicatedStorage.Remotes.Punch.OnServerEvent:Connect(function(player,damage)
for i,target in pairs(game.Workspace:GetDescendants() ) do
if target:IsA("Humanoid") and target.Parent.Name ~= player.Name then
if (target.Parent.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < disatance then
local humanoid = player.Character:WaitForChild("Humanoid")
local leaderstats = player:FindFirstChild("leaderstats").Size.Value
local enemy = game.Players:GetPlayerFromCharacter(target.Parent)
local EnemyLeaderstats = enemy:FindFirstChild("leaderstats").Size.Value
if EnemyLeaderstats < leaderstats then
target:TakeDamage(damage)
elseif EnemyLeaderstats > leaderstats then
humanoid:TakeDamage(damage/2)
end
wait()
else return
end
end
end
end)
That does look a lot cleaner then my very messy scripting, but I am adding on to that script right now and plan on adding another “Mechanic” to my game where there is more specific details too how much damage is taken/given, for example I was thinking of a Gamepass or item where you could survive the attack with low health and thought that for me, using the health = 0 was just more simple for my little monkey brain, I hope that makes sense in any way.