So im trying to give the player speed every second, but when I do this there is no errors found in the output but it does not work, I stayed in the game for 10 minutes and I was still as slow as normal. Heres my script.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Wait for character to load
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Create speed value in leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local speed = Instance.new("IntValue")
speed.Name = "Speed"
speed.Value = 0
speed.Parent = leaderstats
-- Create jump cooldown value
local jumpCooldown = Instance.new("IntValue")
jumpCooldown.Name = "JumpCooldown"
jumpCooldown.Value = 0
jumpCooldown.Parent = leaderstats
-- Create function to update speed
local function updateSpeed()
speed.Value = speed.Value + 1
end
-- Connect to events for updating speed
humanoid.WalkSpeed = speed.Value
humanoid.Jumping:Connect(function()
jumpCooldown.Value = tick() + 1
speed.Value = speed.Value - 5
humanoid.Health = humanoid.Health - 10
end)
RunService.RenderStepped:Connect(function()
if jumpCooldown.Value == 0 or tick() > jumpCooldown.Value then
updateSpeed()
end
end)