#Where should I set GetAttributeChangedSignal for StateManager???

1 messages · Page 1 of 1 (latest)

old hedge
#

I've been wondering where to put my code for my state manager at if it should be on client or server since I was learning state manager with ai. Then gpt was saying it should be on client while Claude was saying its good where its at. I know people regularly say that Claude is better than gpt, but I wanted to get an experienced dev's two cents on this. Anyways heres my code:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(character)
        local CharacterHandler = _G.CharacterHandler
        local characterData = CharacterHandler.new(character)

        --characterData:InitiateAttributeChangedSignal("Stunned")
        --characterData:InitiateAttributeChangedSignal("IsAttacking")

        -- create more later.

        local status = character:WaitForChild("Status")
        
        print("RUNNING!!!")
        --local function UpdateMovement()
        --    characterData:ControlWalkSpeed()
        --    characterData:SetJumpEnabled()
        --end

        local updateMovement = function()
            characterData:UpdateBaseMovement()
            print("UPDATE MOVEMENT")
        end

        status:GetAttributeChangedSignal("Stunned"):Connect(updateMovement)
        status:GetAttributeChangedSignal("GuardBreak"):Connect(updateMovement)
        status:GetAttributeChangedSignal("Slowed"):Connect(updateMovement)
    
        status:GetAttributeChangedSignal("IsBlocking"):Connect(function()
            characterData:ControlWalkSpeed()
        end)

        status:GetAttributeChangedSignal("Sprinting"):Connect(function()
            characterData:ControlWalkSpeed()
        end)


        status:GetAttributeChangedSignal("IsAttacking"):Connect(function()
            characterData:ControlJumpHeight()
        end)
        
        --characterData:SetStatus("Stunned", true)
    end)
end)


#

Also as you can see this is on server as of right now so lemme know if I should change it or if it should stay

lucid yarrow
#

Client

#

Instead of flags, look into using state machines when scripting a combat system (i presume this is what you are making)

#

Also, stay away from AI, not saying to stop but it will benefit you in the long run

old hedge
old hedge
#

Also this script specifically just affects walk speed and jumpheight

glass lynx
#

like what I mean is even if you update them from the server if the client changes them again using a script then they would override the changed made by the server

desert inletBOT
#

studio** You are now Level 17! **studio

glass lynx
#

you can even test this yourself

glass lynx
#

it just depends on the use case

old hedge
glass lynx
#

weird I had tried that before and I had that issue

#

then if so then having your state manager on the server is more saffe

glass lynx
#

because I just tested

#

and ye changing the walkspeed on the client overwrites it

old hedge
#

I'm still trying to get a full understanding of both so I can know which one is best

glass lynx
#

the most recent change will be the one taking effect

old hedge
#

oh yea ur right I went on server and stunned myself then changed my walkspeed on client than it made the stun useless

#

if thats what ur getting at

old hedge
# glass lynx yup

but atp wouldn't everything be on client like animation, vfx, where would be the seperation?

glass lynx
#

trying to keep everything in sync

#

between clientss

old hedge
glass lynx
#

but what you usually do is to prevent false attacks, where the animation loads in the client but the attack doesn't register in the server

#

you do animations and everything which needs to be in sync

#

on the server

old hedge
#

so im going to the server and firing remotes to client basically for the state machine??

glass lynx
old hedge
lucid yarrow
desert inletBOT
#

studio** You are now Level 12! **studio

lucid yarrow
#

That is a flag based system

lucid yarrow
idle goblet
#

I feel like you use two state machines one for the client and one for the server

1.client statemachine -- just works like a normal state machine but for punches or anything that needs validation you ask the server.
2.server statemachine -- will be nearly identical to the player state machine however its job is to make sure the player is in the valid state and just verify their inputs. (movement state would probs be empty since cheaters can just override this but you could maybe add a simple anti cheat here)

old hedge
#

how would this even looks like??

lucid yarrow
# old hedge sooo I need to set something up on server that will limit the client???

client has its own cooldown logic. Sets the state after its cooldown logic finishes and fires a remote to the server. If the server sees that the cooldown did not finish from its perspective, it will tell the client to set its state to the server's perceived current state of the client. How you want to implement this can be totally up to you whether its a remote function, or if you want to use a custom library.

old hedge
old hedge
lucid yarrow
lucid yarrow
old hedge
#

sooo basically client would be like
statehandler("Stunned", true)
remoteevent:FireServer()

And then server would be like:
character:GetAttributeChangedSignal("AttributeNameInsert")":Connect(function()
-- wtv logic inside here that causes stun
end)