Hello there! I just got accepted into the DevForum, and I’m trying to figure out how to add a damage booster to my sword. What I’ve tried to do is when you click a gui button it boosts the damage that your sword is supposed to do.
I’ve done this by putting an IntValue in the sword which will increase every time I buy the +100 damage. The problem is that when I “buy” the damage booster it increases the IntValue but doesn’t deal the added damage.
Code:
local Button = script.Parent
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
local Backpack = player.Backpack
local leaderstats = player.leaderstats
local gold = leaderstats:FindFirstChild("Gold")
if gold.Value >= 100 then
local Katana = game.StarterPack.Katana
Katana.Damage.Value = Katana.Damage.Value + 100
gold.Value = gold.Value - 100
print("You have boosted your Sword's damage")
else
print("Not enough money!")
end
end)
Please tell me if there’s something wrong with my code, or if there’s a better approach to this. I’m open to any criticism.
P.S is there any tips that you can give me on the DevForum? If so thank you and have a wonderful day!
local Handle = script.Parent:WaitForChild("Handle")
local Damage = script.Parent.Damage.Value
Remote.OnServerEvent:Connect(function(Player, Event, IsPlaying, FinalHit)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local damagePart = script.Parent.Handle:WaitForChild("DamagePart")
if Event == "Attack" then
if IsPlaying == true then
game.Workspace.Sounds.Swing:Play()
local hit = false
damagePart.Touched:Connect(function(part)
if not hit and not part:IsDescendantOf(Character) and part.Parent:FindFirstChild("HumanoidRootPart") then
local EnemyRoot = part.Parent:FindFirstChild("HumanoidRootPart")
local EnemyHumanoid = part.Parent:FindFirstChild("Humanoid")
if EnemyHumanoid then
hit = true
print(Damage)
EnemyHumanoid:TakeDamage(Damage)
game.Workspace.Sounds.sliced:Play()
if FinalHit == true then
EnemyHumanoid:TakeDamage(Damage + Damage/2)
end
end
end
end)
end
end
end)
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
local Backpack = player.Backpack
local leaderstats = player.leaderstats
local gold = leaderstats:FindFirstChild("Gold")
if gold.Value >= 100 then
local Katana = backpack.Katana
local DamageServer = game.ReplicatedStorage.Damage
DamageServer:FireServer(Katana)
gold.Value = gold.Value - 100
print("You have boosted your Sword's damage")
else
print("Not enough money!")
end
end)
You are modifying the damage of the Katana in StarterPack.
Use this code:
Client:
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
local Backpack = player.Backpack
local leaderstats = player.leaderstats
local gold = leaderstats:FindFirstChild("Gold")
if gold.Value >= 100 then
local Katana = Backpack.Katana
local DamageServer = game.ReplicatedStorage.Damage
DamageServer:FireServer(Katana)
gold.Value = gold.Value - 100
print("You have boosted your Sword's damage")
else
print("Not enough money!")
end
end)