Hello, I make a system that filling watering can. The normal duration is 20 seconds. But I have a problem. Help me.
If you see, at the end, i need to press multiple time to finish filling. It’s not normal…
Here is the script for the filling :
local prompt = script.Parent.ProximityPrompt
local CanFill = true
prompt.PromptButtonHoldBegan:Connect(function(plr)
local char = plr.Character
local WateringTool = plr.Backpack:FindFirstChild("WateringCan") or char:FindFirstChild("WateringCan")
prompt.HoldDuration = WateringTool.Duration.Value
if WateringTool.Fill.Value < 100 and CanFill == true then
CanFill = false
repeat wait()
WateringTool.Fill.Value += 1
WateringTool.Duration.Value -= 0.2
wait(0.2)
if WateringTool.Fill.Value >= 100 then
break
end
print(WateringTool.Duration.Value)
until CanFill == true
end
end)
prompt.PromptButtonHoldEnded:Connect(function(plr)
CanFill = true
local char = plr.Character
local WateringTool = plr.Backpack:FindFirstChild("WateringCan") or char:FindFirstChild("WateringCan")
prompt.HoldDuration = WateringTool.Duration.Value
print("STOP")
end)
havent really looked that deep into the code but i dont think you are resetting the hold duration value after filling, why are you even changing the hold duration value in the first place?
Because, if the player don’t want to fill the entire of the watering can, the prompt holding duration will change. For exemple : I fill 1/2 of my watering can, if I i want to fill the rest, the prompt will have 1/2 of the base time which is 20 seconds
you can award him by each second of the prompt trigger being active instead of reducing the hold duration and break when the prompt is no longer being used
Try this and let me know, i just modified it a little also use task.wait() instead of wait() because wait() will yield the whole script where as task.wait() wont yield