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

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

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.

local ClickDet = script.Parent.ClickDetector
local ClickTog = script.Parent.ClickToggle

while true do
	if ClickTog.Value == true then
		ClickDet.MaxActivationDistance = 15
	else 
		ClickDet.MaxActivationDistance = 0
	end
	
end

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

✓ Accepted answer

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

Use this simple fixed script:

local ClickDet = script.Parent.ClickDetector
local ClickTog = script.Parent.ClickToggle

while true do
	wait()

    if ClickTog.Value == true then
        ClickDet.MaxActivationDistance = 15
    else 
        ClickDet.MaxActivationDistance = 0
    end
end

1 comment

0

This worked! Thanks!

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

local ClickDet = script.Parent.ClickDetector
local ClickTog = script.Parent.ClickToggle

ClickTog.Changed:Connect(function() -- Will run if ClickTog property has changed
    if ClickTog.Value == true then
        ClickDet.MaxActivationDistance = 15
    else 
        ClickDet.MaxActivationDistance = 0
    end
end)

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