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

Why won't this script save player data?

So i've made this script that's suppose to remember how many stages the player has completed and how many trophies he's collected but it won't work even tho it doesn't show any errors.If any1 has any ideas or suggestions i'm all ears.

Thanks for your time

data = game:GetService('DataStoreService'):GetDataStore('MobbyProgres')

game.Players.PlayerAdded:connect(function(p) -- Player joins
	
local stats = Instance.new ("IntValue",p)
	stats.Name = "leaderstats"
	
	local stage = Instance.new("IntValue", stats)
	stage.Name = "Stage"
	stage.Value = 1
	
	local trophies = Instance.new("IntValue",stats)
	trophies.Name = "TrophiesFound"
	trophies.Value = 0
	
	key = 'Pinfo_'..p.userId 

	
	if data:GetAsync(key) ~= nil then 
		
		stage.Value = data:GetAsync(key)[1]
		trophies.Value = data:GetAsync(key)[2]	
	
	else 
		data:SetAsync(key, {1,0}) 
		
	end
end)

game.Players.PlayerRemoving:connect(function(p) 
	key = 'Pinfo_'..p.userId 
	local save = {p.leaderstats.stage.Value, p.leaderstats.trophies.Value}
	data:SetAsync(key, save) 
end)

2 comments

0

that made 0 difference

0

I've found the error thank you all for your trouble

1 answer

✓ Accepted answer

You name your values "Stage" and "TrophiesFound", but you attempt to save "stage" and "throphies".

Fun fact: You did get errors, but you didn't see them cause it errors the moment you leave.

2 comments

0

yes i figured it out but so did you so you get an accepted answer from me

0

Heh, thanks :)

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