Help on intvalue

i believe this should work. If i understood correctly

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
	 
		if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
			return
		else
			 amount = Instance.new("IntValue")
			amount.Parent = goi
		end
		
		 amount = goi:FindFirstChildOfClass("IntValue")
			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)

Just for the part when you were checking the amount.Value thingies, you can replace those with this.

the value is not increasing,` i think it has to do with the first section of the code

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
		db = false
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1
			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
	else
		print(hit.Parent.Name)
		end
	end	
end)
hit.Parent.Name == "Tree"and db == true

yeah i have no idea what that part of your script does, but if you think that’s the problem yeah go ahead get rid of it.

Wait a minute it’s not working becuase you spelt it wrong. “Amout” Oh you actually named it that.

ok to give you some backstory, this script is supposed to when i click the tree and when the handle it touches it increases the value on a intvalue which makes the visual inscrease and once it does the tree fales over

Wait a minute it might be cuz u make db = false before it can even be added so the conditions of the if statement aren’t even met

db = false -- the stuff below this is not happening?
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1

Or is the stuff below db = false running?

when i remove the db = fasle it creates mutlible intvalues

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
		local modelCFrame = tree:GetPivot()
		goi.CanvasGroup.Visible = true
		amount.Value += 1
		if amount.Value < 5 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
                db = false
		task.wait(1)
		db = true
		end
	else
		print(hit.Parent.Name)
	end	
end)

try this

it did not create a intvalue form some reason

try this

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
	 
		if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
			
		else
			 amount = Instance.new("IntValue")
			amount.Parent = goi
		end
		
		 amount = goi:FindFirstChildOfClass("IntValue")
			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)


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
activated = false
handle.Parent.Activated:Connect(function()

	for i,hit in workspace:GetPartsInPart(handle) do
		if hit.Parent.Name == "Tree"and db == true  then
			local amount

			if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that

			else
				amount = Instance.new("IntValue")
				amount.Parent = goi
			end

			amount = goi:FindFirstChildOfClass("IntValue")
			local tree = hit.Parent
			db = false
			local modelCFrame = tree:GetPivot()
			goi.CanvasGroup.Visible = true
			amount.Value += 1
			print(amount.Value)
			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
end)

Whenever the player clicks using the tool it gets all the parts the handle is touching and if the tree is one of them then it runs the script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.