#Why isn't this variable being incremented by 1?

1 messages · Page 1 of 1 (latest)

true flame
#

LOCAL SCRIPT

while(true) do
    
    totalStancePoints = char:GetAttribute("StancePoints")
    
    
    if totalStancePoints == nil then
        totalStancePoints = 4
    end
    
    totalStancePoints += 1
    if totalStancePoints > 4 then
        totalStancePoints = 4
    end
    
    warn(totalStancePoints)
    
    setStancePoints:FireServer(totalStancePoints)
    updateStanceGUIEvent:Fire(totalStancePoints)
    
    task.wait(1)
end

SERVER SCRIPT
setStancePoints function:

local rs = game:WaitForChild("ReplicatedStorage")
local setStancePoints = rs.SetStancePoints

local stateManager = require(rs.StateManager)

setStancePoints.OnServerEvent:Connect(function(plr, number)
    
    stateManager.SetPermState(plr, "StancePoints", number)
    
end)

MODULE SCRIPT
stateManager function:

function module.SetPermState(plr, stateKey, value)

    plr:SetAttribute(stateKey, value)
    
end
#

File Locations:

gritty yoke
# true flame File Locations:

Both client and server get their own versions of StateManager when they require it. They do not share it. Two copies, not the same one

true flame
gritty yoke
latent dock
#

Aren't you supposed to use setattribute?

true flame
# gritty yoke Nope

but im calling the server script to call stateManager, so the attribute gets changed there, then I get the wanted attribute by doing plr/char:GetAttribute()
or does that change nothing?

true flame
#

might just be complicating my life here

latent dock
#

From my knowledge getattributes = 4 doesn't create the attribute or change it

white crane
true flame
#

doesn't change anything

white crane
#

Although just taking the raw value from remote is bottom 1 ideas

#

Exploiters finna have a field day with this one

latent dock
#

I don't think totalstancepoints = 4 would work.

white crane
true flame
gritty yoke
white crane
latent dock
#

Isn't firing a remote event every second inefficient when everything in the local script can be done on server

true flame
#

i need the player but i dont know how i would get the player in a server script

#

wait

#

starterplayerscripts would prolly work no?

white crane
latent dock
#

For _ players on players:getplayers

#

Assuming you already made players

true flame
white crane
# true flame wdym

He's saying to iterate through all players and run the function on server

true flame
#

OHHH okay yeah

#

i could actually

latent dock
#

local Players = game:GetService("Players") -- Get the Players service

for _, player in Players:GetPlayers() do -- Loop through each player
    print(player.Name) -- Print the name of the current player
end
#

Ik it's ai but I don't have access to my computer rn

true flame
#

would sending data from the server to the client as bad as sending data from the client to the server?

fair quarryBOT
#

studio** You are now Level 9! **studio

white crane
true flame
#

ah

elder sand