Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make it so when a value is true a property is different than if it is false?

Asked by 5 years ago

I have got another script that keeps toggling the ClickTog on and off ( true and off). And when it is true I want the ClickDetector's MaxActivationDistance to be 15 and when it is false it'll be 0. Here's what I came up with so far.

01local ClickDet = script.Parent.ClickDetector
02local ClickTog = script.Parent.ClickToggle
03 
04while true do
05    if ClickTog.Value == true then
06        ClickDet.MaxActivationDistance = 15
07    else
08        ClickDet.MaxActivationDistance = 0
09    end
10 
11end

The ClickToggle is a Bool Value and both the ClickDetector and the ClickToggle have the same parent. The script for the toggling of the Bool Value works just fine but this one makes it so even if the Bool Value is false the MaxActivationDistance is still 15 as if it was true.

2 answers

Log in to vote
0
Answered by 5 years ago

Its probably because you didnt add a wait(), otherwise the script crashes and possibly studio too

Use this simple fixed script:

01local ClickDet = script.Parent.ClickDetector
02local ClickTog = script.Parent.ClickToggle
03 
04while true do
05    wait()
06 
07    if ClickTog.Value == true then
08        ClickDet.MaxActivationDistance = 15
09    else
10        ClickDet.MaxActivationDistance = 0
11    end
12end
0
This worked! Thanks! ANormalPlayer_Alex 11 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I think using while true do isn't very efficient so here is my way how to do it

01local ClickDet = script.Parent.ClickDetector
02local ClickTog = script.Parent.ClickToggle
03 
04ClickTog.Changed:Connect(function() -- Will run if ClickTog property has changed
05    if ClickTog.Value == true then
06        ClickDet.MaxActivationDistance = 15
07    else
08        ClickDet.MaxActivationDistance = 0
09    end
10end)

Answer this question