How to create Super Mario 64 style star system?

forgot to add the respawn part, just add Player:LoadCharacter() after adding 1 to the CollectedAmount value

3 Likes

Tried to add datastore to it and it half worked. The amount of stars saved but the stars reappear when rejoining. Any idea on how to implement that?

local StarsEvent = game:GetService("ReplicatedStorage").StarsEvent
local Players = game:GetService("Players")
local Stars = workspace:WaitForChild("Stars")
local DataStoreService = game:GetService("DataStoreService")
local StarSave = DataStoreService:GetDataStore("StarSave")

local IsCollected = function(Player, Star)
	local Collected = Player:FindFirstChild("CollectedStars")
	if (Collected == nil) then return end 
	
	for i,v in pairs(Collected:GetChildren()) do 
		if (v.Value == Star) then 
			return true 
		end
	end
	return false
end

for i,v in pairs(Stars:GetChildren()) do
	if (v.Name == "Star") and (v:IsA("Part")) then 
		v.Touched:Connect(function(Hit:BasePart)
			local Player = Players:FindFirstChild(Hit.Parent.Name)
			if (Hit.Parent:FindFirstChild("Humanoid")) and (Player ~= nil) then 
				local Collected = IsCollected(Player, v)

				if (Collected == false) then 
					StarsEvent:FireClient(Player, v)

					Player.leaderstats.CollectedAmount.Value += 1 
			

					local StarSave = Instance.new("ObjectValue")
					StarSave.Value = v 
					StarSave.Name = "Star"
					StarSave.Parent = Player.CollectedStars
					
					Player:LoadCharacter()
				end
			end
		end)
	end
end 

Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	
	local CollectedAmount = Instance.new("NumberValue")
	CollectedAmount.Name = "CollectedAmount"
	CollectedAmount.Parent = Leaderstats
	
	local StarsFolder = Instance.new("Folder")
	StarsFolder.Name = "CollectedStars" 
	StarsFolder.Parent = Player
	
	local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveStar")
	local Key = Player.UserId
	local Data = DataStore:GetAsync(Key)
	
	if Data then
		CollectedAmount.Value = Data
		StarsFolder.Value = Data
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Key = player.UserId
	local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveStar")
	DataStore:SetAsync(Key,player.leaderstats.CollectedAmount.Value)
	DataStore:SetAsync(Key,player.leaderstats.StarsFolder.Value)
end)


Hmm, ill look into it i don’t know…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.