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

How do i make a demo game like a timed one?

So i want the player to be able to play a free version of my game but once the time is up they will be kicked just so they get a sneak peek of my game so if they like it they can purchase it.

1 answer

You could do it with a leader stats and make a value of how many seconds or minutes or whatever they have been on the game and once they reach that amount kick them and use datastores to keep track then kick them if they join if they have already filled up their amount of time. You could also not store it if you want them to be able to join again.

I Believe this code should fit your purpose. btw should go in ServerScriptService

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("playerData")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local time = Instance.new("IntValue")
	time.Name = "Time"
	time.Parent = leaderstats
	
	data = playerData:GetAsync(player.UserId.."-time") 
	
	local TimeLimit = 1
	
	if time.Value == TimeLimit then
		playerData:SetAsync(player.UserId.."-time", player.leaderstats.time.Value)
		game.Players:WaitForChild(player.name):Kick("Demo is up!")
	end
	
	
	while true do
		wait(60)
		time.Value = time.Value + 1
		
		if time.Value == TimeLimit then
			playerData:SetAsync(player.UserId.."-time", player.leaderstats.time.Value)
			game.Players:WaitForChild(player.name):Kick("Demo is up!")
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	playerData:SetAsync(player.UserId.."-time", player.leaderstats.time.Value)
end)

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