Help on intvalue

It added mutlible int values how do i make it only have one, im new to scripting so it would be greatly apprieated if I could get some help.

local handle = script.Parent
local Players = game:GetService("Players")
local goi = Players.LocalPlayer.PlayerGui.Gui
local Tween = game:GetService("TweenService")
rotation = CFrame.Angles(0,0, math.rad(90))
db = true

handle.Touched:Connect(function(hit)
	if hit.Parent.Name == "Tree"and db == true  then 
		local amount = Instance.new("IntValue")
		amount.Parent = goi
		local tree = hit.Parent
		db = false
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1
		if amount.Value == 1 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.20,0,0,75)
		end
		if amount.Value == 2 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.4,0,0,75)
		end
		if amount.Value == 3 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.6,0,0,75)
		end
		if amount.Value == 4 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.8,0,0,75)
		end
		if amount.Value == 5 then
			goi.CanvasGroup.Amount.Size = UDim2.new(1,0,0,75)
			tree:PivotTo(modelCFrame * rotation)
			amount:Destroy()
			goi.CanvasGroup.Visible = false
			goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
		end
		task.wait(1)
		db = true
	else
		print(hit.Parent.Name)
	end	
end)

do you mean everytime the Touched function runs it adds more than 1 int value? or to that one gui it adds more than 1 int value and you want to limit it to 1?

yeah i want it to be one character also hw would i change it to when the tool is activated and touched
then do the fucntion

what are you trying to do your code looks so newbie

im trying to make a tree fall down when it reaches 6 on the vlaue and it has a visual for it, im bad at scripting but good atr ui sooo

To make it only add 1 int value, you can make an if statement to check

if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
return
else
-- your code here (basically everything below your if hit.Parent.Name statement)

this is correct but wouldnt it be better to name it and use :FindFirstChild(name) since they might have other values in that part/gui

it does limit it to only one but it does not increase the value at all

He could, but he didn’t give it a name I believe. Also I like doing findfirstchildofclass because roblox then does the autocomplete thing when you’re writing. I think you know what I mean.

It should, did you put the rest of your code in the else statement?

yea like this right?

local handle = script.Parent
local Players = game:GetService("Players")
local goi = Players.LocalPlayer.PlayerGui.Gui
local Tween = game:GetService("TweenService")
rotation = CFrame.Angles(0,0, math.rad(90))
db = true

handle.Touched:Connect(function(hit)
	if hit.Parent.Name == "Tree"and db == true and goi:FindFirstChildOfClass("IntValue") then 
		if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
			return
		else
		local amount = Instance.new("IntValue")
		amount.Parent = goi
		local tree = hit.Parent
		db = false
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1
		if amount.Value == 1 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.20,0,0,75)
		end
		if amount.Value == 2 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.4,0,0,75)
		end
		if amount.Value == 3 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.6,0,0,75)
		end
		if amount.Value == 4 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.8,0,0,75)
		end
		if amount.Value == 5 then
			goi.CanvasGroup.Amount.Size = UDim2.new(1,0,0,75)
			tree:PivotTo(modelCFrame * rotation)
			amount:Destroy()
			goi.CanvasGroup.Visible = false
			goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
		end
		task.wait(1)
		db = true
		end
	else
		print(hit.Parent.Name)
	end	
end)

thats what i do when i use it for humanoids XD

Lmao same, relatable. XD I love doijgn that

if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
print("Idk")
else
-- your code here (basically everything below your if hit.Parent.Name statement)

This has no reason to work but just try it I swear i had the same issue before

His solution is wrong because it will only do it once you can try

local handle = script.Parent
local Players = game:GetService("Players")
local goi = Players.LocalPlayer.PlayerGui.Gui
local Tween = game:GetService("TweenService")
rotation = CFrame.Angles(0,0, math.rad(90))
db = true

handle.Touched:Connect(function(hit)
	if hit.Parent.Name == "Tree"and db == true  then 
                if goi:FindFirstChild("Amout") ~= true then
		local amount = Instance.new("IntValue")
		amount.Parent = goi
                amount.Name = "Amout"
		local tree = hit.Parent
                end
		db = false
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1
		if amount.Value == 1 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.20,0,0,75)
		end
		if amount.Value == 2 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.4,0,0,75)
		end
		if amount.Value == 3 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.6,0,0,75)
		end
		if amount.Value == 4 then
			goi.CanvasGroup.Amount.Size = UDim2.new(0.8,0,0,75)
		end
		if amount.Value == 5 then
			goi.CanvasGroup.Amount.Size = UDim2.new(1,0,0,75)
			tree:PivotTo(modelCFrame * rotation)
			amount:Destroy()
			goi.CanvasGroup.Visible = false
			goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
		end
		task.wait(1)
		db = true
	else
		print(hit.Parent.Name)
	end	
end)

But doesn’t he only want to do this once.

well i want you to be able to cut mutlible trees

By the way to optimize your code you can just do

if amount.Value < 5 then -- checks if its below 5
goi.CanvasGroup.Amount.Size = UDim2.new(0.20,0,0,75)
end
if amount.Value == 5 then
			goi.CanvasGroup.Amount.Size = UDim2.new(1,0,0,75)
			tree:PivotTo(modelCFrame * rotation)
			amount:Destroy()
			goi.CanvasGroup.Visible = false
			goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
		end

You can put the int value in the tree itself

Is this for the whole code or what?