Hi I’m Ted.
This is my first time posting in this thread but I want to know how my interaction script is. I noticed that there was one little bug but other than that it works–I mean I honestly can’t say it works since this bug is present but it does work. Looks like whenever you double click/triple click/quadruple click while the interaction is already filling, it automatically fills a SECOND time immediately after the first interaction fill is finished, although it’s delayed so when the second one happens it starts on like the 5th or 6th fill part.
Basically what happens is you walk up to this invisible part and you click with a pickaxe equipped, and it should fill to represent your progress on collecting that resource.
Video:
Place File:
Interaction code review.rbxl (106.3 KB)
Specific Code:
local TweenService = game:GetService('TweenService')
local UserInputService = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemotesFolder = ReplicatedStorage:WaitForChild('Remotes')
local GetDataRemoteFunction = RemotesFolder:WaitForChild('GetData')
local UpdateData = RemotesFolder:WaitForChild('UpdateData')
local RunService = game:GetService('RunService')
local player = game:GetService("Players").LocalPlayer
local Pickaxe = script.Parent
local PickaxeHandle = script.Parent.Handle
--local DataService = require(game.ServerStorage.Systems.DataService)
resources = {}
for i,v in pairs(workspace.Resources:GetChildren()) do
if v:IsA('Model') or v:IsA('BasePart') then
table.insert(resources, v)
end
end
function IsPlayerInProximity(value)
for i,v in pairs(workspace.Resources:GetChildren()) do
if v:IsA('Model') or v:IsA('BasePart') then
table.insert(resources, v)
end
if (player:DistanceFromCharacter(v.Main.Position) <= 10) then
local prompt = game.ReplicatedStorage.Assets.Prompt:Clone()
prompt.Parent = v.Main
local offset = Vector3.new(0,0,5)
prompt.CFrame = v.Main.CFrame*CFrame.new(offset)
return true
end
end
end
function IsValidCollectable( Object )
return Object:IsA('BasePart') or Object:IsA('Model')
end
local activeData = nil
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,
false,
0
)
--local juice =
--local tween = TweenService:Create(image, tweenInfo)
local holding = false
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and player.Character:FindFirstChild('Pickaxe') then
holding = true
print("Collecting")
local Prompt = workspace:FindFirstChild('Prompt')
local fills = Prompt.BillboardGui.Circle:GetChildren()
for i = 1,#fills do
wait(0.0001)
local temp = "Fill"..tostring(i)
Prompt.BillboardGui.Circle[temp].Visible = true
end
print("Collected")
for i = 1,#fills do
--wait(0.0001)
local temp = "Fill"..tostring(i)
Prompt.BillboardGui.Circle[temp].Visible = false
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and player.Character:FindFirstChild('Pickaxe') then
holding = false
print("Cancelled Collecting")
end
end)
Pickaxe.Activated:Connect(function(LocalPlayer, Object, value)
for i,v in pairs(game.Workspace.Resources:GetChildren()) do
--hmmmm..
if (player:DistanceFromCharacter(v.Main.Position) <= 8) then
local mouse = player:GetMouse()
if mouse.Target.Name == "Main" then
print("Collected +1 "..v.Name)
activeData = GetDataRemoteFunction:InvokeServer()
print(activeData)
print(activeData.Inventory[v])
activeData.Inventory[v.Name] += 1
mouse.Target.Parent:Destroy()
print(activeData)
--for itemID, quantity in pairs(activeData.Inventory) do
-- print(activeData)
--end
end
end
end
end)