MainFrame.StressBall.MouseButton1Click:Connect(function()
if CanPress.Value == true then
Equip(ShopTools["Stress Ball"], ShopTools["Stress Ball"].Name)
else
print("Can press = false") -- This one works
end
end)
MainFrame.CheeseSteak.MouseButton1Click:Connect(function()
if CanPress.Value == true then
Equip(ShopTools["Cheese Steak"], ShopTools["Cheese Steak"].Name)
else
print("Can press = false") -- This one prints this even though it is set to true
end
end)
You can see in the script what is going on. Is there a way I know why this is happening?
The main purpose of this script is basically an inventory system, but it’s unrelated.
The print in the first function doesn’t print (which is good), but the second print does print (which isn’t good)
The CanPress is acting as a cooldown for how fast the player can press the button
I’ll give you more lines above:
PressedEvent.Event:Connect(function()
if CanPress.Value == true then
CanPress.Value = false
task.wait(Cooldown.Value)
CanPress.Value = true
end
end)
MainFrame.StressBall.MouseButton1Click:Connect(function()
if CanPress.Value == true then
Equip(ShopTools["Stress Ball"], ShopTools["Stress Ball"].Name)
else
print("Can press = false") -- This one works
end
end)
MainFrame.CheeseSteak.MouseButton1Click:Connect(function()
if CanPress.Value == true then
Equip(ShopTools["Cheese Steak"], ShopTools["Cheese Steak"].Name)
else
print("Can press = false") -- This one prints this even though it is set to true
end
end)
I think it may be related to CanPress. Maybe it would be better if you made it an internal value? Try that then if it doesn’t get fixed tell me, I’ll try helping further
By the way, for your if statements, you could just do “if CanPress.Value then” instead of “== true”
(don’t think it changes anything but imo it looks better)
local CanPress = true
PressedEvent.Event:Connect(function()
if CanPress then
CanPress = false
task.wait(Cooldown.Value)
CanPress = true
end
end)
MainFrame.StressBall.MouseButton1Click:Connect(function()
if CanPress ~= nil then
print("Not nil")
else
print("Is nil")
end
if CanPress then
Equip(ShopTools["Stress Ball"], ShopTools["Stress Ball"].Name)
else
print("Can press = false")
end
end)
MainFrame.CheeseSteak.MouseButton1Click:Connect(function()
if CanPress ~= nil then
print("Not nil")
else
print("Is nil")
end
if CanPress then
Equip(ShopTools["Cheese Steak"], ShopTools["Cheese Steak"].Name)
else
print("Can press = false")
end
end)
I did this, and they both print “Not nil”
So the cheese steak function does recognize the CanPress but doesn’t do anything about it??
MainFrame.StressBall.MouseButton1Click:Connect(function()
print(CanPress) -- prints true
if CanPress then
Equip(ShopTools["Stress Ball"], ShopTools["Stress Ball"].Name)
else
print(CanPress) -- doesnt print because it's true
print("Can press = false")
end
end)
MainFrame.CheeseSteak.MouseButton1Click:Connect(function()
print(CanPress) -- prints false
if CanPress then
Equip(ShopTools["Cheese Steak"], ShopTools["Cheese Steak"].Name)
else
print(CanPress) -- prints false
print("Can press = false")
end
end)
--[[MainFrame.StressBall.MouseButton1Click:Connect(function()
print(CanPress) -- prints true
if CanPress then
Equip(ShopTools["Stress Ball"], ShopTools["Stress Ball"].Name)
else
print(CanPress) -- doesnt print because it's true
print("Can press = false")
end
end)]]
MainFrame.CheeseSteak.MouseButton1Click:Connect(function()
print(CanPress) -- prints false
if CanPress then
Equip(ShopTools["Cheese Steak"], ShopTools["Cheese Steak"].Name)
else
print(CanPress) -- prints false
print("Can press = false")
end
end)
I’m gonna tab into this logic, clearly the code works. Show the portion of the code where your updating the CanPress value as that’s where the issue is most likely occurring
I think I know why. You should put the canpress changing action inside one of the other functions. This is because you are changing the value to false before you check if it is true. Do this with your original script and not the ones they gave you.