Unable to cast value to object

Alright so im not gonna lie or anything, this is my like 5th or 6th time making this topic, so basically… I GOT THIS LEADERSTATS SCRIPT THAT IS SUPPOST TO save the players clothes so they dont have to buy it again after rejoining

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

	local character = player.Character or player.CharacterAdded:Wait()
	local Cash = player.Character.Shirt.ShirtTemplate
	 ds:GetAsync(player.UserId, character:WaitForChild("Shirt").ShirtTemplate, character:WaitForChild("Pants").PantsTemplate)

	local character = player.Character or player.CharacterAdded:Wait()
	ds:SetAsync(player.UserId, character:WaitForChild("Shirt").ShirtTemplate, character:WaitForChild("Pants").PantsTemplate) --Change "Points" to the name of your leaderstat.

and when i playtest the game i get the error “Unable to cast value to object”

1 Like

You need to save the shirt and pant ids, not the actual object.

Tutorial for further help: https://www.youtube.com/watch?v=xoui5hR_8IE

1 Like

bro no joke, i have no experience with datastores and i don’t know how to do that.

1 Like

okay so i got stuck at this part

if success and data then --If UserId and Data found then
		points.Value = data[1] --Sets points to the first set of data
		wins.Value = data[2] --Sets wins to the first set of data
	else --If UserId or Data not found then
		print("The Player has no Data!") --Player has no data

i don’t know what do i do.

People have given you more than enough resources to complete this task. You shouldn’t repost your topic when you don’t get the answer you want.

1 Like

bro, i literally tried them all and nothing worked.

1 Like