Hello, so I am trying to make “Get Faster Every Second” type game. I know I am going to get a lot of hate in this post but oh well. However, I was wondering how I can make it so at spawn, the player’s speed is stuck at 50 and when they go off spawn their speed will go back to what their stats is. I already have the script and everything, I am just trying to figure out how to make it so the player’s speed is locked at spawn so the player doesnt go flying off at spawn. If you know anything that can stop this, please let me know, thank you.
Can you please provide a script?
Sure thing.
local startingSpeed = 1
local increment = 1
local period = 1
function calculateSpeedIncrease(wins)
local increase = increment + wins
return increase
end
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("DATA STORE")
function saveData(plr)
if not plr:FindFirstChild("DATA FAILED TO LOAD") then
local speed = plr.leaderstats.Speed.Value
local wins = plr.leaderstats.Wins.Value
local compiledData = {speed, wins}
local success, err = nil, nil
while not success do
success, err = pcall(function()
datastore:SetAsync(plr.UserId, compiledData)
end)
if err then
warn(err)
end
task.wait(0.03)
end
end
end
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for _, plr in pairs(game.Players:GetPlayers()) do
saveData(plr)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
local dataFailedWarning = Instance.new("StringValue")
dataFailedWarning.Name = "DATA FAILED TO LOAD"
dataFailedWarning.Parent = plr
local success, plrData = nil, nil
while not success do
success, plrData = pcall(function()
return datastore:GetAsync(plr.UserId)
end)
task.wait(0.03)
end
dataFailedWarning:Destroy()
if not plrData then
plrData = {startingSpeed, 0}
end
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
local speedVal = Instance.new("IntValue")
speedVal.Name = "Speed"
speedVal.Value = plrData[1]
speedVal.Parent = ls
local winsVal = Instance.new("IntValue")
winsVal.Name = "Wins"
winsVal.Value = plrData[2]
winsVal.Parent = ls
ls.Parent = plr
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("Humanoid").WalkSpeed = speedVal.Value
plr.Character:Clone(function(char)
char:WaitForChild("Humanoid").WalkSpeed = speedVal.Value
end)
end)
function handleWinPad(winpad)
local onDebounce = {}
local debounceTime = 3
winpad.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
if plr and not onDebounce[plr] then
onDebounce[plr] = true
plr:LoadCharacter()
plr.leaderstats.Speed.Value = startingSpeed
plr.leaderstats.Wins.Value += tonumber(winpad.Name) or 1
task.wait(debounceTime)
onDebounce[plr] = nil
end
end)
end
for _, winpad in pairs(workspace:WaitForChild("WinPads"):GetChildren()) do
handleWinPad(winpad)
end
workspace.WinPads.ChildAdded:Connect(handleWinPad)
while true do
task.wait(period)
for _, plr in pairs(game.Players:GetPlayers()) do
local plrLS = plr:FindFirstChild("leaderstats")
if plrLS then
local plrSpeed = plrLS:FindFirstChild("Speed")
local plrWins = plrLS:FindFirstChild("Wins")
if plrSpeed and plrWins then
local increase = calculateSpeedIncrease(plrWins.Value)
plrSpeed.Value += increase
if plr.Character and plr.Character:FindFirstChild("Humanoid") then
plr.Character.Humanoid.WalkSpeed = plrSpeed.Value
end
end
end
end
end
I did follow a bit of a tutorial because I am not the greatest scripter xD. But I did make my own adjustments there and there.
Does anyone know how I can do it?