Greetings,
I am trying to make a system that rewards premium subscribers periodically (for example 500 coins / 20 minutes of continuous playing). How can I make a script that detects if a player has premium and starts the system?
Greetings,
I am trying to make a system that rewards premium subscribers periodically (for example 500 coins / 20 minutes of continuous playing). How can I make a script that detects if a player has premium and starts the system?
https://developer.roblox.com/en-us/api-reference/property/Player/MembershipType
Here’s an example script.
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
if player.MembershipType == Enum.MembershipType.Premium then
humanoid.WalkSpeed += 4 --4 extra speed for premium users.
end
end)
end)
If you already have the Leaderstats folder/system, You can award them by writing the code below where it says “Player is in Game, Award them.”, You can also modify the “AwardInterval” variable. (Beware that it only works with numbers from 1 and above, Changing it to decimal numbers like 0.5 won’t work)
Let me know if it works!
-- Variables
local Players = game:GetService("Players")
local AwardInterval = (20 * 60) -- 20 Minutes / First number is the time in Minutes
-- Main
Players.PlayerAdded:Connect(function(Player: Player)
if Player.MembershipType == Enum.MembershipType.Premium then
task.spawn(function()
while task.wait(AwardInterval) do
if Player and Player.Parent then
-- Player is in Game, Award them.
else
-- Player is not in Game, Break the loop.
break
end
end
end)
end
end)
Thanks a lot, this will come very good for usage!
But at the AwardInterval, can’t I do 1 * 30? For 30 seconds.
Yes, You can. I did it as 20 * 60 since 60 makes it 20 minutes straight away, But feel free to modify it!
Thanks once again! (char limit)