How to make "detect" Value and do something? "if, elseif"

–sorry for asking help. :c

  1. I wanted to make that it’s checking after triggering “ProximityPrompt” how many candies he has and if he has under 150 it’s doing something, if he has exactly 150 it’s doing something and if he has more than 150 then it’s going to do something.

It means, I was trying:

if Candies == 150 then
-- script here about exactly
end
elseif Candies > 150 then -- i tried to make if he has more than 150.
-- script here when you have more than 150 (that's example).
end

-- But I can't find how to detect lower than 150 and it can't detect Value.
  1. The issue is that it can’t detect Value.

  2. Yes, I tried to find good helpful ones, but it still don’t work for me.

PromptVariable.Triggered:Connect(function(playerwhoTriggered)
if playerwhoTriggered.Candies == 150 then
-- script here about exactly
end
elseif playerwhoTriggered.Candies > 150 then -- i tried to make if he has more than 150.
-- script here when you have more than 150 (that's example).
end
end)

Make sure the script is server sided, also it wont work with the client script since it tells you the player who triggered it. I hope this helps :heart:

Yeah, but I forgot to say it’s about IntValue. and it’s LocalScript.

if IntValue == 150 then
--script
end

Make it a Server SIded Script, or normal script. And make sure if you have a variable for the Instance of IntValue, don’t forget to do Variable.Value!

Some flaws inside your code
first off, assuming “Candies” is a ValueBase that is storing your data, you should do Candies.Value to detect the value or change it

second, use debounces so the client cannot spam the proximity prompt and listen to it in the server

thirdly, there’s an extra “end” here:

if Candies == 150 then

end --Remove this
elseif Candies > 150 then -- i tried to make if he has more than 150.

end

Sorry for the mistake I’ve made @Doxelix , turns out it CAN work in a client script, but if your script is originally in the workspace then it may not be working. Try parenting it to the ServerStorage and clone the script to each player that joins. Then I believe it may work. Also as UMirin said, there is an extra end in your code.

1 Like

I can say that this script is originally in StarterGui.

And about with debounces and Candies.Value I guess it will work.

Only in

end --Remove this (I need to remove it or not?)

Use debounce if you only want it to do the if statement ONCE.

or untill a condiiton is fulfilled.

I mean… I can use it this too… maybe.

local ProximityPrompt = workspace.Guy.Torso.ProximityPrompt

--script here
ProximityPrompt.Enabled = false
--script
wait(4)
ProximityPrompt.Enabled = true
--the end of script

That’ll look more appealing as you won’t see the prompt anymore. Good job!

Ok. I will go try it. Maybe it will work. :confused:

I never said it couldn’t work in a client, but if it is an important thing it should be handled on the server with its appropriate debounces

@Doxelix if you are working on something important disabling the proximity prompt in the client is also exploitable

Nah. that game is one player slot only. LoL.

if Candies < 150 then
-- Lower
elseif Candies >= 150 then
-- Equal
elseif Candies > 150 then
-- Higher
end
1 Like

you can do something like

if Candies < 150 then
-- your script
elseif Candies == 150 then
-- your second script
elseif Candies >= 150 then
-- your final script
end

If you do that, it will do something if its lower than 150, if its equal to 150 and if its higher than 150. So if you want something who happens only with higher than 150, you can do it, same with less and equal.

And if you’re thinking that “huh uh there is candies >= 150 so it will also happen with 150” you are wrong because the equals 150 is before that, so if its 150 it will never encounter the “>= 150”

Hope it will helps!

(edit for the second equal, forgot it)