#heartbeat

1 messages · Page 1 of 1 (latest)

abstract kraken
#

is this good idea to stop heartbeat to be always work ?

#
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)
plush cape
#

hmm

abstract kraken
#

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 ?

plush cape
#

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

abstract kraken
plush cape
#

that's how i heard ig

plush cape
abstract kraken
plush cape
#

wait let me script

#

a quick example

abstract kraken
#

ok so i dont need run service if there is something named hold ?

plush cape
abstract kraken
plush cape
#

and also everthing you're going to be triggering with is going to increase the amount of coins

abstract kraken
#

better than all this shit i do it lol

#

ok so how i use it ? @plush cape

plush cape
abstract kraken
#

ok

plush cape
#

🙏

#

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

abstract kraken
#

what the hell

#

what is this Y_Y

cinder nebula
#

whats the point of adding deltaTime if ur not gonna use it

#

timepassed+=deltaTime
if timpassed>=.5 then … timepassed = 0 end

plush cape
plush cape
abstract kraken
#

my brain got alot of errors now i will just go

plush cape
# abstract kraken 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

abstract kraken
#

what is current time number ?

#

like what is tick number

plush cape
#

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

abstract kraken
#

i will leave run service and go data store better but ty alot for your helping @plush cape

abstract kraken