How do you change the damage something does?


I am not the best scripter so I have come here for a bit of help… I have a baseball bat inside my game and I would like to lower the amount of damage is does to a player, I have looked through the script myself and are unable to find where it could be or how to do it, here is the script below

If anything else is needed please let me know!

There is a variable called ‘damage’ on line 3, change it to however much you want the damage to be.

Yeah, I did try that however it did not seem to work, it stayed as the same damage it originally was if that makes sense.

@straykevin Your solution wouldn’t work because during the Attack and Lunge functions it gets set to those specific values.

The correct values for damage are on line 8 in the first table. Sadly there are no comments to know which one is which.

So im assuming what your saying is if I change these number it should change the damage it does to a plater?Screenshot 2021-10-21 142506

It appears so, but I must say this code isn’t the best formatted so it is hard to read. In the OnActivated Function it sets the damage variable to a value in the damages table.

Yeah that did work, I thank you for the help.

I see, but then again I would like to understand the point of having damage on line 3 if it’s going to end up with another fixed value later on.

I got this script given to me by someone a while ago, and I would not have any clue.

It’s just declaring the variable, and in this case initializing it as well. It is better to declare variables if you will be using them globally. Writing damages[1] a bunch of times will get 1. repetitive, 2. hard to read.

What I was getting at is that, wouldn’t it be easier to understand the values of damage at a certain line of code if the code had 3 separate variables initialized for the respective damages instead of manually changing a single variable to represent the damage at different times.

For example,

--Initializing various damages
local Damage = 10
local slashDamage = 20
local lungeDamage = 30

instead of having the current code

local damage = 30

local damages = {10,20,30}

-- Change Damages at different points
damage = damages[1]
damage = damages[2]
damages = damages[3]

This would be one of suggestions for the current code to make it more readable.

But also to OP,
let me know if Kaworu’s solution fixed your current problem with your code. I’m sure we’ll both be more than glad to continue offering our assistance to you.