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

Why is my script is not checking if two conditions are met?

I am making a script for a store GUI, upon clicking the buy button I want the script to first check if the player clicking the button is on a certain team, if so then proceed to check if the player has the right amount of money. If not, then do not do anything. However, nothing is happening

Here is my function

local player = game.Players.LocalPlayer
local currency = player:WaitForChild('leaderstats').Coins
local itembutton = script.Parent
local amount = 50
local item = game.ServerStorage.RedPotion
local newitem = item:clone()

itembutton.MouseButton1Click:connect(function()
	if player.TeamColor == BrickColor.new("Bright Yellow") and currency.Value >=amount and (not player.Backpack:FindFirstChild('RedPotion') or player.Character:FindFirstChild('RedPotion')) then
	newitem.Parent = player.Backpack
	currency.Value = currency.Value - amount
	itembutton.Text = 'Purchased'
	itembutton.TextColor3 = BrickColor.Yellow().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.White().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.Yellow().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.White().Color
	else
	itembutton.Text = 'Failed to purchase'
	itembutton.TextColor3 = BrickColor.Red().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.White().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.Red().Color
	wait(0.1)
	itembutton.TextColor3 = BrickColor.White().Color
	wait(0.1)
	itembutton.Text = indextext
	end
end)

What am I doing wrong here?

1 comment

0

"Bright Yellow" on line 2 should be "Bright yellow"

1 answer

Try this for line 9:

if currency.Value >=amount and (not player.Backpack:FindFirstChild('RedPotion') or player.Character:FindFirstChild('RedPotion')) then

You need to put ()'s around stuff you want checked first, kinda like a math equation, like how 5 / (1 + 1) would be 2.5, but 5 / 1 + 1 would be 6.

1 comment

0

I was not aware of that tidbit of advice, I added that in to my script. If you were wondering, it still does not "fix" anything though I am certain adding that in there was still good. In my code in OP...I am scripting it correctly, no? Why is Roblox not reading it? Can I not have two conditions or something?

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