Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this vendor give the item using leaderstats?

So, i'm working on a zombie survival game and i'm working on scripting the weapon pickups, but when I click the part that the script and ClickDetector is in, it doesn't do anything, even when I set points to over 800. And it worked fine without me trying to set a price in "Points" (the currency of the game)

local Points = game.ServerScriptService.leaderboard.leaderstats.Points --I have a leaderboard script that keeps track of what wave you're on and how many points you have
function hi(x)
if Points >799
then
		
	local y = x.Backpack
	local z = game.ReplicatedStorage["AK47"] --Changes the tool that it gives, I have tested without adding the points and it gave me the weapon
	if wait()
	then
		Points = Points - 800
	end
	z:Clone().Parent = y
end

script.Parent.ClickDetector.MouseClick:connect(hi)

1 answer

✓ Accepted answer

###This is because you attempted to compare a user data with number. You will need to add a .Value if Points is a ValueBase. Also please indent your code correctly, it is extremely messy and cannot be read.

local ServerScriptService = game:GetService("ServerScriptService")
local Points = ServerScriptService.leaderboard.leaderstats.Points --I have a leaderboard script that keeps track of what wave you're on and how many points you have

local function hi(x) -- use local functions 
    if Points.Value >= 800 then--check the value! 

        local y = x.Backpack
        local z = game.ReplicatedStorage["AK47"] --Changes the tool that it gives, I have tested without adding the points and it gave me the weapon
        Points.Value = Points.Value - 800--subtract the value! 
   
        z:Clone().Parent = y
    end
end

script.Parent.ClickDetector.MouseClick:Connect(hi) -- connect is deprecated, use Connect

1 comment

0

okay, sorry. Thank you so much for fixing it, now I see how I went wrong with a lot of the code, i'm still learning and this was really helpful!

This discussion is preserved as it was. New answers, comments, and votes are closed.