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

explain the script to make a speeddatastore so that players who rejoin can get their speed back?

Asked by 4 years ago
Edited 4 years ago

I have made a speed change script

local player = game.Players.LocalPlayer 
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") local wins = player.leaderstats.Wins 
local value = 10
wins.Changed:Connect(function() humanoid.WalkSpeed = humanoid.WalkSpeed + value end)

1 answer

Log in to vote
1
Answered by 4 years ago

LocalScript (ClientScript)

local player = game.Players.LocalPlayer 
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local wins = player.leaderstats.Wins 
local value = 10

wins:GetPropertyChangedSignal('Value'):Connect(function()
    humanoid.WalkSpeed = humanoid.WalkSpeed + (value * wins.Value) / 2
end)

ServerScript (Script)

--< Services
local PlayerService = game:GetService('Players')
local RStorageService = game:GetService('ReplicatedStorage')
local DataStoreService = game:GetService('DataStoreService')

--< Variables
local DataStore = DataStoreService:GetDataStore('Datas')

--< Events
PlayerService.PlayerAdded:Connect(function(player)
    local l = Instance.new('Folder', player)
    l.Name = 'leaderstats'
    local w = Instance.new('IntValue', l)
    w.Name = 'Wins'
    w.Value = DataStore:GetAsync(player.UserId) or 0
end)

PlayerService.PlayerRemoving:Connect(function(player)
    if player:FindFirstChild('leaderstats') then
        DataStore:SetAsync(player.UserId, player.leaderstats.Wins.Value)
    end
end)

Hope this help, to more questions put bellow in commentaries.

Ad

Answer this question