2 Scripts contrasting, how do I fix?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? For my Wood.Value to go up only when an axe is hitting the log

  2. What is the issue? Currently working on a simulator game, I have a script so that the tree is hit when my Axe tool hits it, however another script hits the tree when the humanoid makes contact with the log to add to my WoodValue

  3. What solutions have you tried so far? I’ve tried to find other results and tried myself, however as they’re 2 different scripts i am unsure on how to work with them.

Script 1

local z = script.Parent
local x = z.Log
local y = z.Leaves
local hits = 0
local hitsN = 3
x.Touched:connect(function(hit)
	if hit.Parent.Name == "Axe" then
		hits = hits + 1	
		if hits == hitsN then
			hits = 0
		end
	end
end)

Script 2

local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.leaderstats.Wood.Value = player.leaderstats.Wood.Value + 1
			script.Parent.Transparency = 1
			wait (10)
			db = true
			script.Parent.Transparency = 0
		end
	end
end)

Would really appreciate support on this, I’ll make sure to review the recommendations. I’m not a skilled scripter, as you can see my title is Artist, however I am exploring other areas and I recently have been getting hooked into scripting.

Not sure what your problem is, but if you want it to only add 1 to the value only when the axe touches the wood, you will need to delete line 8 from Script 2. You would need to put that line in Script 1, when it checks to see if the axe hit the wood.

Thank you, this actually helped a lot. I’ve decided to add more features to the tree that’s making it actually fun to use, but I couldn’t do without your assistance.

1 Like