Shop GUI Problem

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)
Error

Anyone have even an inkling of what’s wrong here? Have never worked with HD admin’s API thingy.

2 Likes

The GUI’s items and script location:
image

1 Like

I really need help with this. Can I please get a response?

1 Like

You forgot to put :Connect.

script.Parent.MouseButton1Click:Connect(function(plr)

My god I’m such a fool.

char limit

1 Like

Okay, solved that problem. It still won’t execute. The error now:

I don’t see how this is an issue. The code is in the original post, but here’s the line with the error:

local cash = plr:WaitForChild("leaderstats", math.huge):WaitForChild("Cash", math.huge)

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")
1 Like

Tried this, but same error.
image

1 Like

Can you show me your modified script?

1 Like
--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.

You haven’t even defined gui as a variable, just change it to script.Parent since the script is under the gui button.

local plr = script.Parent:FindFirstAncestorWhichIsA("Player")

Crap. I haven’t scripted in a year or so, sorry. I really need to get the hang of this again.

All fixed, thanks so much for staying with me through my stupid blunders :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.