Can anyone help me in making a script that gives a gamepass owner a certain amount of Coins when they join the game and not get anymore even if they keep leaving and joining back.
I have an idea of using leaderstat values to make this, but I was wondering if there another way to do this?
If anyone can send some script examples of this for me to try it would be much appreciated and if anyone has any questions or wants to see the way I would do it - feel free to ask!
local MarketPlaceService = game:GetService("MarketPlaceService ")
local PlrOwns = MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)
if PlrOwns then
-- Give player coins
end
you dont have to put any userId in this since the game can detect if you’re the owner by game.CreatorId
local YourGamePassId = 1 -- Change 1 to your gamepass ID
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId ~= game.CreatorId then return end -- Checks if the Player Is The Owner if not it will not continue.
local GamePassCheck = game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(game.CreatorId,YourGamePassId)
if GamePassCheck then
-- stuff
else
warn("There Was An Error")
end
end)
The game is created by a group, I am the only person who has access to the place but the game itself is published on a group. Will that affect anything such as the CreatorId?
local YourGamePassId = 1 -- Change 1 to your gamepass ID
game.Players.PlayerAdded:Connect(function(plr)
local GamePassCheck = game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(plr.UserId,YourGamePassId)
if GamePassCheck then
-- stuff
else
warn("There Was An Error")
end
end)
Paste this script in a Regular Script in ServerScriptService.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("MarketplaceService")
local passId = 000000 -- Change this to your gamepass ID
Players.PlayerAdded:Connect(function(player) -- This is the event that detects when a player joins
local Coins = player.leaderstats.Coins.Value
local hasReceived = Instance.new("BoolValue") -- Create a boolean value that determines whether the player has already earned the coins or not
hasReceived.Parent = player
hasReceived.Name = "hasReceived"
hasReceived.Value = false
if MarketplaceService:UserOwnsGamepassAsync(player.UserId, passId) and hasReceived.Value == false then
player.leaderstats.Coins.Value += 50 -- Change the number to however many coins you want the player to receive.
hasReceived.Value = true -- Sets the Boolean Value to true so the player will not receive the coins when they join again.
end
end)
Won’t this script insert a bool value every time the player joins?
Even if the player leaves and rejoins it isn’t like the boolen value that was created last time will be there instead a new one will be created allowing the user to get coins by rejoining.
I think it would be better to use datastores as the value will be saved even if player rejoins.