#heartbeat
1 messages · Page 1 of 1 (latest)
local userinputservice = game:GetService("UserInputService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local coins = plr:WaitForChild("leaderstats"):FindFirstChild("Coins")
local hold = false
local runservice = game:GetService("RunService")
local connection
userinputservice.InputBegan:Connect(function(input , GPE)
if GPE or not coins then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
hold = true
if hold then
connection = runservice.Heartbeat:Connect(function(deltaTime)
if hold then
coins.Value +=1
else
connection:Disconnect()
end
end)
end
end
end)
userinputservice.InputEnded:Connect(function(input , GPE)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
hold = false
end
end)
hmm
oh wit i will change something
local userinputservice = game:GetService("UserInputService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local coins = plr:WaitForChild("leaderstats"):FindFirstChild("Coins")
local hold = false
local runservice = game:GetService("RunService")
local connection
userinputservice.InputBegan:Connect(function(input , GPE)
if GPE or not coins then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
hold = true
if hold then
connection = runservice.Heartbeat:Connect(function(deltaTime)
if hold then
coins.Value +=1
end
end)
else
connection:Disconnect()
end
end
end)
userinputservice.InputEnded:Connect(function(input , GPE)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
hold = false
end
end)
now ?
bro why you making a hold = true thing
u could use umm userinputservice.inputHoldBegan, userinputService.inputHoldEnded
and looks like you're increasing the amount of coins from client side
which means it won't replicate to the server
so the coins will not be saved when the player joins later
yeah i will add remote event but i want to know is this will make runservice disconnect ?
holdbegan ?
yeah i see that you created connection:Disconnect() and you should also use connection = nil after that to i guess not let client memory leak
that's how i heard ig
yeah
what is this ?
ok so i dont need run service if there is something named hold ?
uhm... you can use run service i guess that's fine but it will increase the amount of coins too fast do you want that?
yeah but if there is something named hold so i will use it
and also everthing you're going to be triggering with is going to increase the amount of coins
give me a minute
ok
my bad, i thought it was ProximityPromptService for a minute but the things you only have to change is ummm make a debounce for the coins and make a remoteEvent for it
🙏
let me show you how you make a cooldown
even with runService
-- services
local runService = game:GetService("RunService")
--values
local now = tick()
local cooldownTime = 0.5
-- signals
runService.PreRender:Connect(function(deltaTime)
if tick() - now >= cooldownTime then
print(cooldownTime)
now = tick()
end
end)
here you can use tick to make a debounce
whats the point of adding deltaTime if ur not gonna use it
timepassed+=deltaTime
if timpassed>=.5 then … timepassed = 0 end
this is good 👍
idk man doesn't rlly matter much
yeah you can do like that too
my brain got alot of errors now i will just go
bro it's simple don't get confused
now = tick() -- which gets the current time
if tick() - now >= cooldownTime then -- if the current time - previous time which is the thing we named now bigger or equal to >= 0.5 means that if it's bigger or equal to 0.5 then
-- here we do
now = tick() -- updating the time to current else it will be like go ahead from 0.5 to 1,2,3,4,5,6,6,6,7,7,7,7,8,8,9, blablabla
end
an example
local now = tick() -- an example let's just say this 10
if tick() -- let's just say this 15
if 15 - 10 >= 0.5 then -- 15 - 10 is bigger than 0.5
now = tick() -- and the 15 which is the time been is going to be here
end
it will continue going like uhh
if 20 - 15 >= 0.5 blalblalblalblalblvla
don't think deep on it dude
it's just enough if you're able to do it
i will leave run service and go data store better but ty alot for your helping @plush cape
yw
i understand it now , its very good