I want my weapon's values such as damage etc2 to be based on player stats (and make the tool be able to change the player stats without problems too), and make it interact with the enemy player's stats and the player itself. What would be the best approach for a tool to interact with player stats so I won't have any trouble may the tool be a weapon, armor, shield, etc2.
This is my current script (in local, tried to convert it to server, didn't work)
wait(0.1)
local tool = script.Parent
local Player = game.Players.LocalPlayer --get the local player
local Mouse = Player:GetMouse() --get the mouse
local isitEquipped = Player.hasWeapon
local cooldown = 0
local onCooldown = false
local canDamage = false
local critChance
function onClick ()
if isitEquipped.Value == true and script.Parent.Parent.ClassName == "Model" and cooldown == 0 then
local attack = tool.Parent.Humanoid:LoadAnimation(script.Attack) -- script.Parent is tool so just use tool.Parent
attack:Play()
attack:AdjustSpeed(script.Parent.itemSpeed.Value)
print("clicked")
cooldown = 1/script.Parent.itemSpeed.Value
wait(1/script.Parent.itemSpeed.Value)
cooldown = 0
end
end
function damageEnemy (enemy)
local getName = enemy.Parent.Name
local enemyPlayer = game.Players:FindFirstChild(getName)
if cooldown ~= 0 then
if not canDamage then
canDamage = true
if enemy.Parent:FindFirstChild("Monster") then
critChance = math.random(1,100)
if critChance <= (script.Parent.itemCritical.Value*(Player.Stats.Dexterity.Value/10)) then
enemy.Parent.Monster:TakeDamage(script.Parent.itemCritDamage.Value*script.Parent.itemDamage.Value)
else
enemy.Parent.Monster:TakeDamage(script.Parent.itemDamage.Value*(1+(Player.Stats.Strength.Value/100)))
end
wait(script.Parent.itemSpeed.Value)
elseif enemy.Parent:FindFirstChild("Humanoid") and enemyPlayer.Pvp then
if enemyPlayer.Pvp.Value == true then
critChance = math.random(1,100)
if critChance <= (script.Parent.itemCritical.Value*(Player.Stats.Dexterity.Value/10)) then
enemy.Parent.Humanoid:TakeDamage(script.Parent.itemCritDamage.Value*script.Parent.itemDamage.Value)
else
enemy.Parent.Humanoid:TakeDamage(script.Parent.itemDamage.Value*(1+(Player.Stats.Strength.Value/100)))
end
wait(script.Parent.itemSpeed.Value)
end
end
canDamage = false
end
end
end
Mouse.Button1Down:connect(onClick)
script.Parent.Part.Touched:connect(damageEnemy)
I tried somewhere along the lines on changing the stats with this server script:
player = script.Parent.Parent
function addStat()
print("AAA")
if script.Parent.itemEquipped.Value == true then
player.Stats.Strength.Value = player.Stats.Strength.Value + 50
elseif script.Parent.itemEquipped.Value == false then
player.Stats.Strength.Value = player.Stats.Strength.Value - 50
end
end
script.Parent.itemEquipped.Changed:Connect(addStat)
But it doesn't even work or print "AAA"

2 comments
On line 09 for the first one it self the variable hasnt been given any extension
That isn't the error. That is perfectly fine in Lua.