So I have this script that will give you a hammer and set Hammer.Value to true etc. But when I set it to true the elseif statement will react because the hammer value is true which causes my code to not work properly. Could someone help me?
local Hammer = game.ReplicatedStorage.Tools.Hammer:Clone() local Replicator = game.ReplicatedStorage.Replicators.Shop.Purchase_Hammer local Audio_Ctr = game.ReplicatedStorage.Replicators.Misc.Audio_Controller local Button = workspace.Shop.Hammer_Item.Purchase_Button local Purchase_Sound = "Purchase_Sound" local insufficient_Funds = "Err_Purchasing" Replicator.OnServerEvent:Connect(function(player) local Currency = player:WaitForChild("Currency") local Bits = Currency.Bits local Own_Hammer = player.ToolStat.Hammer --<-->-- if Bits.Value >=10 and Own_Hammer.Value == false then Bits.Value = Bits.Value -10 Hammer.Parent = player.Backpack Audio_Ctr:FireClient(player,Purchase_Sound) print("True") Own_Hammer.Value = true elseif Bits.Value <=10 or Own_Hammer.Value == true then print("FALSE") Audio_Ctr:FireClient(player,insufficient_Funds) end end)
I may be wrong but I believe it has to do with how you wrote the if and elseif statements. For example if Bits.Value is 10 because >= implies that if it's bits.Value is bigger or EQUALED to 10 then and so on. That's the same for the OTHER Bits.Value if statement, implying that if Bits.Value is smaller or EQUALED to 10. So either way both if statements will give you "true" therefore running the code. Also for the elseif statement make sure to change it to "and" instead of "or", so that it will absolutely work and the value must be both true and less than 10. Tell me if the code below doesn't work.
local Hammer = game.ReplicatedStorage.Tools.Hammer:Clone() local Replicator = game.ReplicatedStorage.Replicators.Shop.Purchase_Hammer local Audio_Ctr = game.ReplicatedStorage.Replicators.Misc.Audio_Controller local Button = workspace.Shop.Hammer_Item.Purchase_Button local Purchase_Sound = "Purchase_Sound" local insufficient_Funds = "Err_Purchasing" Replicator.OnServerEvent:Connect(function(player) local Currency = player:WaitForChild("Currency") local Bits = Currency.Bits local Own_Hammer = player.ToolStat.Hammer --<-->-- if Bits.Value >=10 and Own_Hammer.Value == false then Bits.Value = Bits.Value -10 Hammer.Parent = player.Backpack Audio_Ctr:FireClient(player,Purchase_Sound) print("True") Own_Hammer.Value = true elseif Bits.Value < 10 and Own_Hammer.Value == true then print("FALSE") Audio_Ctr:FireClient(player,insufficient_Funds) end end)