#Need help debugging m1 system

1 messages · Page 1 of 1 (latest)

meager pier
#

snippet:

local lastCombo: IntValue = character.Core:WaitForChild("LastCombo")
    local lastSwing: IntValue = character.Core:WaitForChild("LastSwing")
    local swingNumber: IntValue = character.Core:WaitForChild("SwingNumber")
    local MAX_COMBO: IntValue = 4

    if (os.clock() - lastCombo.Value) < DataValues.ComboCooldown then return end
    if (os.clock() - lastSwing.Value) >= DataValues.M1Reset then
        swingNumber.Value = 1
        print("Reset combo to swing 1")
    else
        swingNumber.Value += 1
        print("Continuing combo, swing:", swingNumber.Value)
    end

    if swingNumber.Value > MAX_COMBO then
        swingNumber.Value = 1
        lastCombo.Value = os.clock()
        print("Max combo reached, resetting swings, starting cooldown")
        return
    end

    lastSwing.Value = os.clock()

    local attackingInstance = Instance.new("BoolValue")
    attackingInstance.Name = "M1"
    attackingInstance.Parent = character

    local animator = character.Humanoid:FindFirstChild("Animator")
    local animationToPlay: AnimationTrack = animator:LoadAnimation(animations["L"..tostring(swingNumber.Value)])

    print("Playing animation: L" .. tostring(swingNumber.Value))

    debris:AddItem(attackingInstance, animationToPlay.Length)
    animationToPlay:Play() 

    animationToPlay:GetMarkerReachedSignal("Hit"):Once(function()
        print("Hit marker reached for swing:", swingNumber.Value)

https://cdn.discordapp.com/attachments/614682648350294026/1404340881225551973/51DSwwUDhEpY07bRfeZb7Q.mov?ex=689ad5dd&is=6899845d&hm=9ef1079e5fb392fcfd83c2f0d9cecda2bd664d2bd14e85a5d455f6bb042a5612&

always plays all the anims on the first swing, but works completely fine otherwise

#

apologies for horseshit quality

lavish coyote
meager pier
#

Yeah

#

nothing else seems off about my other scripts so im pretty stumped

meager pier
#

seems to be a problem with using renderstepped

#

problem gets fixed if i switch to a click m1 system but i prefer being able to hold

#

local uis = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:WaitForChild("Remotes")

RunService.RenderStepped:Connect(function(deltaTime: number)
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
remotes.M1Event:FireServer()
end
end)

lavish coyote
#

Hmm

#

The renderstep itself shouldn't be causing a problem. Might mean there's an issue with the cooldown times.

#

wait

#

nvm

meager pier
lavish coyote
#

Discord is messing with the formatting and make it difficult to read 😔

#

try throttling the render step a little bit

#

only theory I have is it's running too fast or something idk

meager pier
#

alright

#

ill try in the morning

#

thanks for the help

lavish coyote
#

After a second look, throttling it a little bit most likely won't do anything

#

so uh, GL

meager pier
#

Spaghetti code problems

worldly tuskBOT
#

studio** You are now Level 2! **studio

meager pier
lavish coyote
#

Well, I put a barebones version of your script into a game rq, and I can confirm it is a problem with that snippet, at the very least

lavish coyote
meager pier
#

yes

lavish coyote
#

Though I also may not have

#

How is the cooldown between punches calculated

meager pier
#

os clock measured using an int value

#

if it reaches a certain threshold it resets swingvalue

lavish coyote
#

Yes, but in the code snippet, there isn't a limit to how fast you can punch, it just requires you to punch before the combo ends

meager pier
#

Hmm

lavish coyote
#

Did you forget to add that to the snippet here, or are you making sure the player doesn't punch too quickly in the local script

#

and if the latter is the case, that might be the problem with the renderstepped version, since it doesn't seem to throttle that

meager pier
#

i dont think i added a limit for that

lavish coyote
#

That might be the problem

meager pier
#

ill look into it

lavish coyote
#

the render stepped is literally just going through the whole combo in a microsecond lol

meager pier
meager pier
#

Tried throttling it but it only slightly delayed the spam

#
local uis = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:WaitForChild("Remotes")

local lastFired = 0
local throttleDelay = 0.2

RunService.RenderStepped:Connect(function(deltaTime: number)
    if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
        local currentTime = tick()
        if currentTime - lastFired >= throttleDelay then
            remotes.M1Event:FireServer()
            lastFired = currentTime
        end
    end
end)
quick forge
#

https://create.roblox.com/docs/reference/engine/globals/RobloxGlobals#tick

Returns how much time has elapsed, in seconds, since the Unix epoch, on the current local session's computer. The Unix epoch is represented by 00:00:00 on 1 January 1970.

tick() isn't officially deprecated, but has a variety of issues. It can be off by up to one second and returns inconsistent results across time zones and operating systems. Use os.time(), os.clock(), or time() instead. Also consider DateTime.UnixTimestamp and DateTime.UnixTimestampMillis.

Built-in functions and constants unique to Roblox.

#

there is also the fact that this remotes.M1Event:FireServer() will have a slight input delay, and can sometimes get get pooled together if you send too many of them too fast and the network can't keep up - rare issue but it can happen

quick forge
# meager pier snippet: ```lua local lastCombo: IntValue = character.Core:WaitForChild("LastCo...

really, the main problem would be the gate here lua if (os.clock() - lastCombo.Value) < DataValues.ComboCooldown then return end if (os.clock() - lastSwing.Value) >= DataValues.M1Reset then swingNumber.Value = 1 print("Reset combo to swing 1") else swingNumber.Value += 1 print("Continuing combo, swing:", swingNumber.Value) end
it doesn't look like you update lastCombo, and your lastSwing.Value gate doesn't block the function

#

so yea, timing is probably off in a few places

meager pier
meager pier
meager pier
#

damn he just egod me

#

Lol

quick forge
#

you said it was fixed so

meager pier
worldly tuskBOT
#

studio** You are now Level 3! **studio

meager pier
#

its still bugged