Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to increase damage based on leaderstat values?

I want the amount of damage you do to be based on your 'strength' in leaderstats and 'rebirths' which is also in leaderstats

For example if you have 1000 strength you do 1000 damage and if you have 1 rebirth you do double that amount(2k) and if you have 2 rebirths you do 4x that amount(4k)

This is what i have so far

local canDoDmg = false
local dmg = 25 
local db = false

local Plr = game.Players.LocalPlayer
local Stats = Plr:WaitForChild("leaderstats")
local Strength = Stats:FindFirstChild("strength")
local UserInputService = game:GetService("UserInputService")
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://6203475027"
local track = Humanoid:LoadAnimation(Anim)

UserInputService.InputBegan:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseButton1 and db == false then 
		track:Play()
		canDoDmg = true
		db = true
		script.Parent.RightHand.Touched:connect(function(hit)
			if hit.Parent.Humanoid and canDoDmg == true then
				hit.Parent.Humanoid:TakeDamage(dmg*Strength)
			end
		end)
		delay(1, function()
			canDoDmg = false
			db = false
		end)
		wait(10)
	end
end)

i got this error on line 22 attempt to perform arithmetic (mul) on number and Instance 

2 answers

On line 22 you are multiplying dmg which is 25, a number, with Strength which is IntValue i assume, you need to turn it into a number, in this case just get it's value and change it to hit.Parent.Humanoid:TakeDamage(dmg*Strength.Value).

You also said you want to be it multiplied by 2 every rebirth so you can fix that using for loop, from your script i assume you know how they work:


...
db = true

script.Parent.RightHand.Touched:connect(function(hit)
	if hit.Parent.Humanoid and canDoDmg == true then
		local TotalDamage = Strength.Value -- default value with 0 rebirths

		for i = 1, dmg do
			TotalDamage *= 2
		end

		hit.Parent.Humanoid:TakeDamage(TotalDamage)
	end
end)
...

I am not sure if dmg stands for rebirths or Strength.Value but if you get how it works, you can make it work.

4 comments

0

dmg is the base damage you do when a new player joins. Also how would i get the strength value from leaderstats i tried -- local strength = Plr.leaderstats.strength.Value and i put in your script and got the error attempt to index number with 'Value' line 23 or in your script line 6

0

the point is that you should not do local strength = Plr.leaderstats.strength.Value but local strength = Plr.leaderstats.strength and then only doing Strength.Value on line 6 to get the newest value. I did not change anything before the script i showed so do not change anything there. if dmg is the damage and Strength.Value is rebirths then you would reverse the values from line 6 to line 9.

0

Ok i think i get it now i changed line 6 to local TotalDamage = dmg + Strength.Value then on line 8 i changed dmg to rb(rebirths) so what i think is happening is that dmg is 25 and if your strength value is 1000 your total damage is 1,025 and for each rebirth it goes up by 2 so 1 rebirth is 2050 total damage and 3 rebirths is 4,100... i think im still new to this, im working on a npc to check

0

yea looks like rebirth dont affect anything i even gave myself billions of rebirths, im completely clueless on how to do this

I suppose you already have a damage script. This is my guess:

local damage = -- put your damage here

game.Players.PlayerAdded:Connect(function(player)
	local strength = player.leaderstats.Strength.Value
	local rebirth = player.leaderstats.Rebirth.Value

	player.damage = strength * rebirth
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.