Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to get script to update value properly?

Asked by 4 years ago

so i have this pretty basic script that is used to update the players speed based on some leaderstast. but the problem i have is it does update the players stats but it ignores the other part of the math equation while doing so. if it doesnt make sense just take a look at the script:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        player.stats.Speed.Changed:Connect(function()
            local mult = character.SpeedMult
            character.Humanoid.WalkSpeed = (player.stats.Speed.Value/mult.Value + 16)
        end)
    end)
end)

so when the players leaderstat Speed is changed its supposed to update the Characters speed. in the math equation it divides the players speed leaderstat with a intvalue called "SpeedMult" i named it mult in the script. when the mult changed through a server script the value might change from dividing the leaderstat with 1500 to maybe 30000 and the players speed stays the same.i want to make it where if the value changes the player gets slower because its being divided by a bigger number. im not sure how to do this though, ive tried doing if the value is changed then update the players speed but then it would only update if the player updates his or her speedmult value. if anyone knows what im trying to do and knows how i can do it then pls help.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I'm going to abstract (meaning put into simple terms) this problem so that it doesn't seem so complicated. I'll give you a simple way to get the character's speed.

Base will be how fast you go by default Divider will be the number that causes your speed to go down as it increases.

--You can set base to the leaderstat value
local base = 50
local divider = 4
--Speed
local speed = base/4
--Set walk speed
character.Humanoid.WalkSpeed = speed

That's all you need.

Ad
Log in to vote
0
Answered by 4 years ago

It was a little hard to understand, but I think your problem is that the SpeedMult variable is stored on the client and you are trying to edit it using a script which is stored on the server.

I'm not an expert, but I think you would need a Remote Event to make the client and server scripts interact with each other.

Unfortunately, I have no clue how to make this work, but I can send you the link to the Remote Event wiki. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Answer this question