I'm trying to make a script that stores the value "Cash" in my script for a sword fighting game. I'm getting the error above on line 15 and I have no idea how to fix it since I got assistance from a YouTube tutorial on how to make this. If anyone could help that would be great.
local maxlevel = 25 game.Players.PlayerAdded:Connect(function(player) local leaderstats = player:WaitForChild("leaderstats") local level = leaderstats:WaitForChild("Level") local xp = leaderstats:WaitForChild("XP") while wait() do local levelvalue = level.Value local xpneeded = ((levelvalue * 2) - 1) * 50 if level.Value < maxlevel then if xp.Value >= xpneeded then level.Value = level.Value + 1 xp.Value = xp.Value - xpneeded end end end end)
Use this if you are making a save cash
Script in workspace
local DataStore = game:GetService("DataStoreService"):GetDataStore("greatneil80") game.Players.PlayerAdded:connect(function(player) local plr = game.Players.LocalPlayer local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" local Gold = Instance.new("IntValue", stats) Gold.Name = "Cash" local key = "player-"..player.userId local savedValues = DataStore:GetAsync(key) if savedValues then --Save format: {points, coins} Gold.Value = savedValues[1] else local valuesToSave = {Gold.Value} DataStore:SetAsync(key, valuesToSave) end end)
then when player leaves... new script in workspace.....
local DataStore = game:GetService("DataStoreService"):GetDataStore("greatneil80") game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId --Save key: {points, coins} local valuesToSave = {player.leaderstats.Cash.Value} DataStore:SetAsync(key, valuesToSave) end)
This should work... Have fun..