Hello, guys! I’ve been trying to make a cash register and it is almost done. But I have a problem.
So, I made a script for the cash register but when I hold to proximity prompt the animation doesn’t play.
-- SETTINGS --
-- [Cash Register] --
local Cooldown = 8 -- The couldown after the rob
local ProximityCooldown = 5 -- The cooldown of the proximity prompt
local MoneyAward = math.random(100, 2000) -- local Money = math.random(minimum, maximum) or local Money = amount
local canBeRobbed = true
local Alarm = "" -- The alarm sound Id
-- [Webhook] --
local WebHookURL = "" -- The webhook URL
-- [Other] --
local proximityPrompt = script.Parent:WaitForChild("Hitbox"):WaitForChild("ProximityPrompt")
local MoneyService = game:GetService("DataStoreService"):GetDataStore("MoneyService")
-- SCRIPTS --
--[[ DELETE THIS LINE IF YOU DON'T HAVE A LEADERSTATS SCRIPT
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Value = "Money"
local data
local success, errormessage = pcall(function()
data = {
MoneyService:GetAsync(plr.UserId)
}
end)
end)
--]] --DELETE THIS LINE IF YOU DON'T HAVE A LEADERSTATS SCRIPT
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Value = "Money"
local data
local success, errormessage = pcall(function()
data = {
MoneyService:GetAsync(plr.UserId)
}
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = {plr.leaderstats.Money}
local success, errormessage = pcall(function()
MoneyService:SetAsync(plr.UserId, data[1])
end)
end)
while wait() do
if canBeRobbed == true then
proximityPrompt.Enabled = true
else
proximityPrompt.Enabled = false
end
proximityPrompt.HoldDuration = ProximityCooldown
end
local robbingAnim = script.RobbingAnim
proximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:FindFirstChild("Humanoid")
hum:LoadAnimation(robbingAnim)
robbingAnim:Play()
end)
end)
proximityPrompt.PromptButtonHoldEnded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:FindFirstChild("Humanoid")
hum:LoadAnimation(robbingAnim)
robbingAnim:Stop()
end)
end)
proximityPrompt.Triggered:Connect(function(plr)
plr.leaderstats.Money.Value += MoneyAward
canBeRobbed = false
wait(Cooldown)
canBeRobbed = true
end)
I tried getting help from roblox studio community servers but I couldn’t find anything useful
try this But I think the animation won’t stop playing
-- SETTINGS --
-- [Cash Register] --
local Cooldown = 8 -- The couldown after the rob
local ProximityCooldown = 5 -- The cooldown of the proximity prompt
local MoneyAward = math.random(100, 2000) -- local Money = math.random(minimum, maximum) or local Money = amount
local canBeRobbed = true
local Alarm = "" -- The alarm sound Id
-- [Webhook] --
local WebHookURL = "" -- The webhook URL
-- [Other] --
local proximityPrompt = script.Parent:WaitForChild("Hitbox"):WaitForChild("ProximityPrompt")
local MoneyService = game:GetService("DataStoreService"):GetDataStore("MoneyService")
-- SCRIPTS --
--[[ DELETE THIS LINE IF YOU DON'T HAVE A LEADERSTATS SCRIPT
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Value = "Money"
local data
local success, errormessage = pcall(function()
data = {
MoneyService:GetAsync(plr.UserId)
}
end)
end)
--]] --DELETE THIS LINE IF YOU DON'T HAVE A LEADERSTATS SCRIPT
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Value = "Money"
local data
local success, errormessage = pcall(function()
data = {
MoneyService:GetAsync(plr.UserId)
}
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = {plr.leaderstats.Money}
local success, errormessage = pcall(function()
MoneyService:SetAsync(plr.UserId, data[1])
end)
end)
while wait() do
if canBeRobbed == true then
proximityPrompt.Enabled = true
else
proximityPrompt.Enabled = false
end
proximityPrompt.HoldDuration = ProximityCooldown
end
local robbingAnim = script.RobbingAnim
proximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
local char = plr.Character
local PlayAnim = char.Humanoid:LoadAnimation(robbingAnim)
PlayAnim:Play()
end)
proximityPrompt.PromptButtonHoldEnded:Connect(function(plr)
local char = plr.Character
local PlayAnim = char.Humanoid:LoadAnimation(robbingAnim)
PlayAnim:Stop()
end)
proximityPrompt.Triggered:Connect(function(plr)
plr.leaderstats.Money.Value += MoneyAward
canBeRobbed = false
wait(Cooldown)
canBeRobbed = true
end)