Exactly what the title says.
I have this sword and I want the damage to be based off a player's leaderstat. For example, if I have 700 power, it's multiplied by .07 and then that's the damage value.
Here's the script I have in the sword:
wait(0.01) CanDamage = true script.Parent.Handle.Touched:connect(function(hum) -- Changed "part" to "hum" if hum and hum.Parent:FindFirstChild("Humanoid") then -- "hum" is the Player who touched the part/Sword. local player = game.Players:GetPlayerFromCharacter(hum.Parent) local plr = player.leaderstats.Power.Value if CanDamage == true then CanDamage = false hum.Parent.Humanoid:TakeDamage(plr * 0.07) -- I forgot to add the "Parent.Humanoid" part after "hum"1 wait(0.8) CanDamage = true end end end)
No errors pop up aswell.
I'd appreciate the help!
ok?
wait(0.01) CanDamage = true script.Parent.Handle.Touched:connect(function(hum) -- Changed "part" to "hum" if hum and hum.Parent:FindFirstChild("Humanoid") then -- "hum" is the Player who touched the part/Sword. local player = game.Players:GetPlayerFromCharacter(hum.Parent) local plr = player.leaderstats.Power.Value local damage = math.ceil(plr * 0.07) if CanDamage == true then CanDamage = false hum.Parent.Humanoid:TakeDamage(damage) -- I forgot to add print(damage) wait(0.8) CanDamage = true end end end)
You have to get the plyer who owns the sword, not the one you hit, I assume this is a server script, and there should be a local script firing an animation or something, So in that local script, fire a Remote Event
instance. These remotes are used for getting the polayer on server scripts, this is how it should look like:
--LocalScript local Remote = game.ReplicatedStorage.RemoteEvent Remote:FireServer() --Server Script local CanDamage = true game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- here we got the player script.Parent.Handle.Touched:connect(function(hum) if hum and hum.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hum.Parent) local plr = player.leaderstats.Power.Value if CanDamage == true then CanDamage = false hum.Parent.Humanoid:TakeDamage(player.Data.Damage * 0.07) wait(0.8) CanDamage = true end end end) end)
Remote Events just allow an access from client to server. And firing a remote when you use the sword will make the sword know the player who used it. I hope I helped.