Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index local "leader" how to fix??

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore ("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local leader = ("Folder")
	leader.Name = "leaderstats"
	local Cash = Instance.new("IntValue", leader)
	Cash.Name = "Cash"
	Cash.Value = ds:GetAsync(player.UserId) or 0
	Cash.Changed:Connect(function()
		ds:SetAsync(player.UserId,Cash.Value)
	end)	
		
	end) 

game.Players.PlayerRemoving:Connect(function(player)
	ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)

1 comment

0

There are multiple things wrong with this.

1 answer

Change line from line 5 to line 8 to:

local leader = Instance.new("Folder")
leader.Parent = player
local cash = Instance.new("IntValue")
cash.Parent = leader
cash.Name = "Cash"

Also, change connect in line 4 to Connect. I'm assuming this isn't your script, so for future reference, please write your own scripts if you're going to ask questions on this website.

5 comments

0

This may not even address all of the problems in your script, but it will at least fix some of them.

0

Actually set the parent last. But yes

0

how is it not my script?

0

Because in previous scripts you were doing it correctly and coincidentally you're now not. Also your first question was an alvinbloxx script.

0

Lol.

This discussion is preserved as it was. New answers, comments, and votes are closed.