How to give people a title after donating from a donation board

I’m trying to script–my guess, correct me if im wrong–an if statement that allows the person who donated to get a title in chat (similar to an admin or owner title) once they donate

If it isn’t an “if” statement, then please do correct me and write the code out so I can use it
Just added info, not sure if it applies, but would a gamepass script work for this type of thing or no?

3 Likes

I believe you could probably find this somewhere in #resources . If not then I will post an answer to this when I have the time

just checked and there’s nothing on it. Keep in mind I have also checked youtube & forums for something similar to this at the most and still have found nothing. But thank you for being willing to post the answer when you have time

I do believe Alvin_Blox posted a tutorial on this, I may be mistaken though.

I think you’re thinking of giving a title via gamepass tutorial by him

You could easily make a donation gamepass and find a tutorial on how to make a title appear when buying a gamepass.

1 Like

The method is very similar, basically you replace everything to do with the gamepass with the stuff about donations. I’ll provide more when I do a tutorial in Resources.

alright. I sorta thought that was the case but was unsure, ty!

You can make a chat script that detects if a player bought a certain gamepass it will trigger it and make a value next of it name like “[DONOR]” or something else, you can watch tutorials if you want so.

Let me tell you what an if statement is:

if
“if” is not an variable, string or integer.

You use if to check if something is something, for example:

if part.BrickColor = BrickColor.new("Really Red") then
-- what it will do if the part's brick color is "really red".
end

Now, on the donation board script there usually is something like:

script.Parent.TextButton.MouseButton1Click:Connect(function()
 MarketPlaceSerivce:PromptPurchase(game.Players.LocalPlayer, gamepassId)
-- what it will do when the player clicks the button thingy
end)

You could make it so that it gives them the tag if the purchase is sucsessful.

BACK TO IF

“if” isn’t alone, it has friends:
elseif
else (technically not an if statement)

elseif lets you check alternative conditions.
else is where you put what it will do if it doesn’t meet the condition, it isn’t required.

Example:

if player.Name == 'airsoft561' then
 character.Humanoid.WalkSpeed = 20
elseif player.Name == 'airsoft562' then
 character.Humanoid.WalkSpeed = 19
else
 character.Humanoid.WalkSpeed = 16
end

This would change the player’s walkspeed if their name is airsoft561 or airsoft562 and the other player’s walkspeed would be ‘16’. (Ofcourse you would need to do game.Players.PlayerAdded:Connect(function(player)and game.Players.CharacterAdded:Connect(function(character) beforehand)

That’s basically it, hope this helped.

If it did: Please mark it as “SOLUTION”!

2 Likes

that’s the exact video I used for the owner title I gave myself, but would it still work if It were from a donation board? (without the gamepasses)

Thank you for more clearly describing an if statement, however, that still doesn’t answer my OP about a script from a donation board w/o gamepasses–if that’s even possible.

Hi! You could make use of DataStores. They basically save data to a DataStore in your place that can be accessed at any time (just not via command bar without a key). You could view more about it from this article or I could explain it really quickly if you’d like. So depending on how your system is set up, you would have to modify it - the main thing is that you understand how it works. So to set up a DataStore you would just add these two lines to the start of every script that requires access to it:

local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")

This would basically allow you to store values into keys within that DataStore. Then, to save their donation (not the Robux just the information) to it, you could do something like this:

local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")

local function donate(donor,amount)
    local ID = donor.UserId -- You could also use game.Players:GetUserIdFromNameAsync()
    DonorStore:SetAsync(ID,tonumber(amount))
end

game.Players.PlayerAdded:Connect(function(plr)
    donate(plr,amount) --Call this function when they donate.
end)

That would be a basic idea of how to save their donation information to the server. If you do not need the amount they donated then you could just remove that. tonumber() was used because if you extracted their amount from a TextLabel, you would need to convert it to a number before saving it (so that you can add to it when necessary). Now to display their donor status, you could do something like:

local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")
game.Players.PlayerAdded:Connect(function(plr)
    local AmountDonated = DonorStore:GetAsync(plr.UserId)
    if AmountDonated > 0 then
        --Give them their donor perks, tag, title or whichever.
    end
end)

All this is just a rough idea, but there are many more precautions you would need to take when using DataStores. For instance, they tend to fail occasionally - especially if too many requests are sent at once or if tables are being stores. To prevent the rest of our script from breaking, we can make use of pcall(). A protected call will ensure that any error returned by a function will stay within the pcall(), and you would be able to work from there. For example:

local success,fail = pcall(function()
    local AmountDonated = DonorStore:GetAsync(plr.UserId)
end)
if success then --Checks if success returns the boolean 'true'.
    if AmountDonated > 0 then
        --Give them their donor perks, tag, title or whichever.
    end
else
    --Let the player know that their donor title has not loaded.
end

This would be the most convenient and efficient approach in my opinion, however if you have no prior experience to handling DataStores you may need to experiment around a lot with them haha. Good luck! :smile:

2 Likes

Thank you so much! This will definitely help, as I’m not too familiar with DataStores just yet. One question though, where would I put these scripts inside? (ex; in a textlabel, datastore, etc?)

No worries! So it depends on how they are donating. For the script that gives them the title:

local DSS = game:GetService("DataStoreService");
local DonorStore = DSS:GetDataStore("DonorStore");
game.Players.PlayerAdded:Connect(function(plr)
    local AmountDonated = DonorStore:GetAsync(plr.UserId);
    if AmountDonated > 0 then
        --Give them their donor perks, tag, title or whichever.
    end;
end);

For the script above, that should be in SeverScriptService (or Workspace, but it would not be safe). Then for this script:

local DSS = game:GetService("DataStoreService");
local DonorStore = DSS:GetDataStore("DonorStore");

local function donate(donor, amount)
    local ID = donor.UserId; -- You could also use game.Players:GetUserIdFromNameAsync()
    DonorStore:SetAsync(ID, tonumber(amount));
end;

game.Players.PlayerAdded:Connect(function(plr)
    donate(plr, amount); --Call this function when they donate.
end);

It should be linked to when they make the donation itself. So when the purchase is prompted and after the purchase it, you can call the function. However if you have no prior experience in doing this it is completely okay, but I think you should learn and do research on these three categories:

I would tell you all I know about them and how you can implement this system, but it would be absolutely useless if you do not know how to use them yourself - since it is your game after all. So just fully understand them and don’t rush it, and you’d know how to use them in no time. Then if you have any questions while learning, you could just create a post so others could help or feel free to shoot me a DM! Good luck. :slightly_smiling_face:

4 Likes

Thank you so much, absolutely so helpful! For now, I created gamepasses for it but I’ll definitely work out the dono system very soon!

I definitely will shoot a DM if needed, have a good one!

1 Like

No problem, glad I could help! Also I advise using Devleoper Products for donations simply because they can donate more than once. For example if you had a two Game Passes; one costing 100 and one costing 1000, they would not be able to donate anywhere in between. However if you have a Developer Product costing 100, they can purchase maybe two of them - donating a total of 200. You have a good one too! :smiley:

Awesome, I’ll make sure to keep that in mind haha