Sword Damage Booster

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. :grinning_face_with_smiling_eyes:

P.S is there any tips that you can give me on the DevForum? If so thank you and have a wonderful day! :heart:

2 Likes

Tip: format your code correctly.
Use ``` to form a code block.

That’s what they’re doing already.

Could you please show the code that is actually dealing the damage? That is the point of interest here.

Sure, here it is

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)
1 Like

I think the problem is that you’re changing the damage value on the client, which won’t replicate to the server. Try adding a remote for that.

It didn’t work. The value didn’t change.

Could you send your client and serverside code?

Okay.

Client Side:

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)
1 Like

Server Side:


DamageServer.OnServerEvent:Connect(function(player, weapon)
	local DamageValue = weapon.Damage.Value
	DamageValue = DamageValue + 100
end)
1 Like

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)

Server:

DamageServer.OnServerEvent:Connect(function(player, weapon)
	local DamageValue = weapon.Damage.Value
	DamageValue = DamageValue + 100
end)
1 Like

Didn’t work. It says Damage is not a valid member of “Players.FWS_TeIIo”

The first argument of OnServerEvent is always the player who fired it. The other arguments come after it.

The value still wont change. Is there any other way to reference it?

Could you update the previous posts of your code?

Note that you’re changing the gold value on the client, so the gold value won’t actually change.

Edit: I see the problem. You are modifying the variable you saved of the DamageValue, and not the actual value.

Use weapon.Damage.Value += 100, this should fix your problem.

It didn’t work again. I’ll send the code again to see if I’m doing it correctly or incorrectly.

Code:


DamageServer.OnServerEvent:Connect(function(player, weapon)
	weapon.Damage.Value += 100
	
	local leaderstats = player.leaderstats
	local gold = leaderstats:FindFirstChild("Gold")
	
	gold.Value = gold.Value - 100
end)

Seems correct, could you try adding a print(weapon.Damage.Value) at the end?

Sure thing.

Output:
Screenshot (42)

It says it’s 110 but when I check the IntValue’s properties, it’s still 10

Can you check if it’s only like that on the server?