Hello everyone. I’m currently making a script for a “speed simulator” using DataStore 2. What I want to do is everytime the player clicks the button, the speed increases and the WalkSpeed also increases. The problem is that even though speed is increasing, the actual WalkSpeed is not. Can you help me?
local ds2 = require(1936396537)
local defaultValue = 1
local defaultIncrement = 1
game.Players.PlayerAdded:Connect(function(p)
local speedStore = ds2("speed", p)
local leaderstats = Instance.new("Folder", p)
leaderstats.Name = "leaderstats"
local speed = Instance.new("IntValue", leaderstats)
speed.Name = "Speed"
local function speedUpdate(updatedValue)
speed.Value = speedStore:Get(updatedValue)
end
speedUpdate(defaultValue)
speedStore:OnUpdate(speedUpdate)
speed.Changed:Connect(function(newValue)
local c = p.CharacterAdded:wait()
local h = c.Humanoid
local s = newValue
h.WalkSpeed = s/100
end)
end)
game.Workspace:WaitForChild("Part").ClickDetector.MouseClick:Connect(function(p)
local speedStore = ds2("speed", p)
speedStore:Increment(defaultIncrement, defaultValue)
end)
game.Workspace:WaitForChild("RedPart").ClickDetector.MouseClick:Connect(function(p)
local speedStore = ds2("speed", p)
speedStore:Set(1)
end)
Thanks for reading!