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

Why does my shop system keep purchasing even when stripebatowned is set to true?

So I'm doing a purchase system and when it's purchased it sets the variable

local batowned

too true, but when I press purchase again it purchases it despite batowned being true.

local stripebatowned = false
player = game:GetService("Players").LocalPlayer
if stripebatowned == false then
script.Parent.MouseButton1Click:Connect(function()
    if player.leaderstats.Credits.Value >= 1000 then
        script.Parent.Text = "Equip"
        local stripebatowned = true
        player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 1000
        end
    end)
end

it should only trigger if stripebatowned = false but it still triggers even when set to true so whats the issue?

1 answer

When you call a function, in your case MouseButton1Click, it doesn't automatically disconnect. What is happening is, the script is checking to see if stripedbatowned == false, if so it connects the mousebutton1down. This results in the function staying connected, and being able to be fired even if stipedbatowned == true. This is because you dont check inside the function itself to see if they own it already. To solve the problem, call the MouseButton1Click function, then check to see if they own it.

local stripebatowned = false
player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if stripebatowned == false then
		if player.leaderstats.Credits.Value >= 1000 then
			script.Parent.Text = "Equip"
			local stripebatowned = true
			player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 1000
		end
	end
end)

2 comments

0

hmm, I tried this an it still keeps purchasing. Your solution makes a lot of sense but it still wont work.

0

This should work. The code wont run unless stripebatowned == false. You can test it by doing print(stripebatowned) after you check it and see what it prints.

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