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?
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)
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.
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)
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)
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