I need help to make my sword damage increase due to the Power Stats.
Here’s my leaderstats script:
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new(“Folder”,player)
stats.Name = “leaderstats”
local score = Instance.new(“IntValue”,stats)
score.Name = “Power”
score.Value = 0
end)
I want to know how i can change the damage that my sword do to the Power leaderstats.
I also need to know how i can change the health to the power leaderstats.
You’re gonna need to detect when the sword has hit the player. If you want assistance with it, you can use Roblox’s sword script, go inside it and see how they do it.
After you have that done, all you need is:
--Define the player
player.leaderstats.Power.Value = player.leaderstats.Power.Value + 0 -- Whatever amount you want it to do each hit.
Use datastore for making saved values.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
tool.Activated:Connect(function()
Player:WaitForChild("leaderstats").Power.Value = Player:WaitForChild("leaderstats").Power.Value + 0.5 --change ammount.
end)
Before I even start: please stop using the parent argument of Instance.new.
Ideally your statistics should, if you’re looking to increase some kind of stat, be multiplicative of some kind of base modifier and additive of an overall base stat. For example, say your sword has a base damage of 16. You’re going to want to then add to this 16 using your stat. As for the stat itself, how it grows is also dependent on your calculations. For example, for every point in Power, 0.15 damage is added to the sword.
You’re looking at the formula baseDmg + (dmgPerPoint * powerPoints)
where baseDmg is the damage the sword starts off with and the equation in the parenthesis shows that a certain base factor should be multiplied by the power points to get the damage increase. The same formula applies for health and anything else where you require a stat to increase a base from something.
With that formula in mind, all you’re doing is filling in where necessary in and around your code. For setting what a Humanoid’s health can be, just detect changes to the power stat and then apply the formula to MaxHealth. For damage, calculate the increase before applying damage.