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

When a player joins a game with players in it, he gets the data of the other player?

So, when I was playing with my friend in my game, when he joined, he got the exact same data as me, but it was the first time joining my game, so that shouldn't be happening. My script:

local purchasedfolder = game.Workspace.PurchasedValues
local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("CarPurchasedDataStore")
game.Players.PlayerAdded:Connect(function(player)
	local key = player.Name.."-"..player.UserId
	local encodedData = nil
	pcall(function()
	encodedData = DataStore:GetAsync(key)
	end)
		if encodedData ~= nil then
	local data = HttpService:JSONDecode(encodedData)
	-- Set the values from the decoding
	purchasedfolder.Purchasedbmw.Value = data[1]
	purchasedfolder.Purchasedgtr.Value = data[2]
	purchasedfolder.Purchasedhoon.Value = data[3]
	purchasedfolder.Purchasedmc.Value = data[4]
	purchasedfolder.Purchasedpor.Value = data[5]
	purchasedfolder.Purchaseds13.Value = data[6]
	print("Loaded all the values")
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local data  = {
    	purchasedfolder.Purchasedbmw.Value,
	    purchasedfolder.Purchasedgtr.Value, 
	    purchasedfolder.Purchasedhoon.Value,
	    purchasedfolder.Purchasedmc.Value,
	    purchasedfolder.Purchasedpor.Value,
	    purchasedfolder.Purchaseds13.Value
	}
	local key = player.Name.."-"..player.UserId
	local normalData = HttpService:JSONEncode(data)
	DataStore:SetAsync(key,normalData)
end)

4 comments

0

You have already posted this before, bruh.

0

I know, but no one answered so I'm allowed to repost.

0

Fine then i'm reposting mine then

0

Hi! I have not learned about DataStore but it seems like you never actually loaded a specific players data. I think it takes the data of the first person that entered and bases that data for other players. Try making your friend go first (make sure he has Dif stats), and check to see if you copy his stats.

1 answer

--Please refer to my comment on your post. (EDITED)

A workaround I can see doing is putting an intvalue/numvalue in your player for the 5 different things in your purchasedfolder.

So it would go like this inside your PlayerAdded script

player:findFirstChild("Purchasedbmw").Value  = data[1]
purchasedfolder.Purchasedbmw.Value = player:findFirstChild("Purchasedbmw").Value -- Purchasedbmw will be the number value or intvalue that you manually add in your player. I believe this will work, but please let me know if it doesn't.

2 comments

0

and do the same thing with the other items in purchasedfolder

0

Ok, I did it like you told me to but it still gives my friend my data, but thank you for trying.

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