Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)

Ad

Answer this question