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

Script not making part cancollidable?

Asked by 6 years ago
Edited 6 years ago

I made this script which goes in a brick. The script should check in startergui if the gui stated in it has the text "-[Completed]." If the text says completed then the brick would be cancollidable.

local debounce = false 

script.Parent.Touched:connect(function(hit)
    if debounce == false then 
        wait()
        debounce = true 
        local player = game.Players:FindFirstChild(hit.Parent)
        if player and Startergui.Quests[player.Name].Frame6.quest6.Value == "-[Completed]" then 
            script.Parent.CanCollide = false
            wait(.5) 
            script.Parent.CanCollide = true
        end
        --I placed the debounce inside the if statement, so that it only gets reset by the function call that set it
        wait(2)
        debounce = false
    end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

You're referencing the GUI the player originally gets, rather than the one he currently has. You'll want to reference the PlayerGui rather than StarterGui. The code should look something like this:

local debounce = false 

script.Parent.Touched:Connect(function(hit)
    if debounce == false then 
        wait()
        debounce = true 
        local player = game.Players:FindFirstChild(hit.Parent)
        if player and player:WaitForChild("PlayerGui").Quests[player.Name].Frame6.quest6.Value == "-[Completed]" then 
            script.Parent.CanCollide = false
            wait(.5) 
            script.Parent.CanCollide = true
        end
        --I placed the debounce inside the if statement, so that it only gets reset by the function call that set it
        wait(2)
        debounce = false
    end
end)

This is what I got from your post at least. Reply to this if your situation is different.

0
Not sure why it didn't work. So basically the Frame6.quest6 is a gui which normally says "-None" but if you touch a brick then it changes to "-[Completed]." So I want the block to only become cancollidable if the gui says Completed but I'm not sure what I'm doing wrong. blingmcqueen 8 — 6y
0
Alright, if you can edit the script so that I can see the part that changes the text in the GUI I could help you further. SystemFormat 149 — 6y
Ad

Answer this question