Hi Devs! I have a problem(im not that good at scripting but i tried all the methods i knew)…
The game is a simulator(like eating simulator)
The problem is, when i click the ball(tool) the animation is ok, but the script that gives the currency doesn’t have a cooldown, so when i spam click the animation is regular, but the click script continue to give me the currency. i tried to put these line of code(that didn’t work for me):
wait(1)
repeat wait() until tool.GripPos == Vector3.new(0,0,0)
local debounce
I also tried to disable the script when the animation is running but it breaks.
So, if you want to help these are my scripts:
Tool animation script(Cloned in every ball):
local Tool = script.Parent
local cooldown = false
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
Tool.GripPos = Vector3.new(0, 0, 0)
wait(0.01)
Tool.GripPos = Vector3.new(0.0, 0, 0.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 1)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 1.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 2)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 2.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 3)
Tool.Bounce:Play()
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 2.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 2)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 1.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 1)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 0.5)
wait(0.01)
Tool.GripPos = Vector3.new(0, 0, 0)
wait(0.60)
cooldown = false
end
end)
Script that fires when i click(tool)(ServerStorage):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
local tool = script.Parent
tool.Activated:Connect(function()
remotes.ToolActivated:FireServer()
wait(1)
end)
ToolManager script where it defines the event that is firing from the previous script(ServerScriptService):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Stats = require(ServerScriptService.Utils.Stats)
local Rewards = require(ServerScriptService.Utils.Rewards)
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
local tools = ServerStorage:FindFirstChild("Tools")
local scripts = ServerStorage:FindFirstChild("Scripts")
local toolConfig = require(ReplicatedStorage:FindFirstChild("Config"):FindFirstChild("ToolConfig"))
remotes.ToolActivated.OnServerEvent:Connect(function(player: Player)
Rewards.Dribbles(player, Stats.Dribbles(player))
end)
for _, tool in ipairs(tools:GetChildren()) do
local script = scripts.Click:Clone()
script.Parent = tool
local animation = scripts.Animation:Clone()
animation.Parent = tool
local bounce = ReplicatedStorage:WaitForChild("Sounds"):WaitForChild("Bounce"):Clone()
bounce.Parent = tool
end
Module script where gives the currency(ServerScriptService):
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local backpackConfig = require(ReplicatedStorage.Config.BackpackConfig)
local Stats = require(ServerScriptService.Utils.Stats)
local Rewards = {}
local function getMaxDribbles(player: Player)
for _, config in ipairs(backpackConfig) do
if config.ID == player.inventory.EquippedBackpack.Value then
return config.Stat
end
end
end
function Rewards.Dribbles(player: Player, amount: number, useMultiplier: boolean)
useMultiplier = if useMultiplier ~= nil then useMultiplier else true
local multiplier = if useMultiplier == true then Stats.DribblesMultiplier(player) else 1
local total = player.leaderstats.Dribbles.Value + (amount * multiplier)
local max = getMaxDribbles(player)
if total > max then
player.leaderstats.Dribbles.Value = max
else
player.leaderstats.Dribbles.Value = total
end
if player.leaderstats.Dribbles.Value == max then
Remotes.MaxDribbles:FireClient(player)
end
end
function Rewards.Coins(player: Player, amount: number, useMultiplier: boolean)
useMultiplier = if useMultiplier ~= nil then useMultiplier else true
local multiplier = if useMultiplier == true then Stats.CoinMultiplier(player) else 1
player.leaderstats.Coins.Value += amount * multiplier
end
return Rewards
Thanks!