Hey all,
I’ve been trying to make a shop item that gives the purchaser admin. This is already a feature in the HD admin docs.
Code
--Retrieve API
hdMain = require(game:GetService("ReplicatedStorage"):WaitForChild("HDAdminSetup")):GetMain()
hd = hdMain:GetModule("API")
--Define the rank-to-reward and setup the corresponding rankId and rankName
rank = "Abuser Admin"
rankType = "Server"
rankId = tonumber(rank) or hd:GetRankId(rank)
rankName = hd:GetRankName(rankId)
script.Parent.MouseButton1Click(function(plr)
local cash = plr:WaitForChild("leaderstats", math.huge):WaitForChild("Cash", math.huge)
cash = cash - 500
--Check rank is lower than giver rank
local plrRankId, plrRankName, plrRankType = hd:GetRank(plr)
if plrRankId < rankId then
--Give rank
hd:SetRank(plr, rankId, rankType)
else
--Error message
local errorMessage = "Your rank is already higher than '"..rankName.."'!"
if plrRankId == rankId then
errorMessage = "You've already been ranked to '"..rankName.."'!"
end
hd:Error(plr, errorMessage)
end
wait(1)
end)
You can’t get a plr from a mouse button 1 click, but you can get the player from a gui (or just any instance that is a descendant of a plr) by doing this.
local plr = gui:FindFirstAncestorWhichIsA("Player")
--In a Server Script
--Retrieve API
hdMain = require(game:GetService("ReplicatedStorage"):WaitForChild("HDAdminSetup")):GetMain()
hd = hdMain:GetModule("API")
--Define the rank-to-reward and setup the corresponding rankId and rankName
rank = "Abuser Admin"
rankType = "Server"
rankId = tonumber(rank) or hd:GetRankId(rank)
rankName = hd:GetRankName(rankId)
script.Parent.MouseButton1Click:Connect(function()
local plr = gui:FindFirstAncestorWhichIsA("Player")
local cash = plr.leaderstats.Cash
cash.Value = cash.Value - 500
--Check rank is lower than giver rank
local plrRankId, plrRankName, plrRankType = hd:GetRank(plr)
if plrRankId < rankId then
--Give rank
hd:SetRank(plr, rankId, rankType)
else
--Error message
local errorMessage = "Your rank is already higher than '"..rankName.."'!"
if plrRankId == rankId then
errorMessage = "You've already been ranked to '"..rankName.."'!"
end
hd:Error(plr, errorMessage)
end
wait(1)
end)
Maybe I should’ve put it elsewhere? I just chucked it into the function.