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

How would I make it when the bool value equals true then it will do something?

uh I need help with this script it is basically where it checks where the bool value is true i tried to put a while loop but i dont work, pls help, here is the code:

local hasQuest = script.Parent.HasQuest
local event = game.ReplicatedStorage.Events.NoQuest

script.Parent.Touched:Connect(function(hit)
	while true do
		wait(1)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if hasQuest.Value == false then
				event:FireClient(player)
		else
			script.Parent.CanCollide = false
			wait(2)
			script.Parent.CanCollide = true
			end
		end
	end
end)

2 answers

ANSWER: GetPropertyChangedSignal. You can use this to make code run when the hasQuest.Value changes.

How:

hasQuest:GetPropertyChangedSignal("Value"):Connect(function()
	if hasQuest.Value == true then
		-- do something
	else
		-- do something
	end
end)

Note: keep in mind, this code will run everytime hasQuest's value changes.

local hasQuest = script.Parent.HasQuest

local debounce = true


script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	       if h~=nil then
		if debounce then
			debounce = false
           if hasQuest.Value == false then
               print("sdkajuhasdkjhdsakjhasdkjasdhkasjdhdsakjdsakjhdsa")
        else
            script.Parent.CanCollide = false
            wait(2)
			script.Parent.CanCollide = true
			end
			wait(2)
			debounce = true
       	end
    end
end)

here you can try this, i chaged the remote thing to print so i could make sure it works, you should know what to put instead.

1 comment

0

debounce so that it doesnt spam whatever the remote event does

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