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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
Roger111 347 Moderation Voter
4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by
quinzt 201 Moderation Voter
4 years ago
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.

0
debounce so that it doesnt spam whatever the remote event does quinzt 201 — 4y

Answer this question