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

Why is my script ignoring a string/instance?

Asked by 2 years ago
Edited 2 years ago

Hi, I'm trying to make a script that detects which "box" you're in and then create/edit one attribute depending on which you're in. For instance, if you're not in any box the default is "none." But if you walk into the red box then it'd become "redBox." When you leave the box it's defaulted back to "none." The issue here is that it's completely ignoring the "redBox" instance's name. My script is below.

local testingRegionsBoxes = game.Workspace:WaitForChild("regionTestingBoxes")
local redBox = game.Workspace.regionTestingBoxes.redBox
local greenBox = game.Workspace.regionTestingBoxes.greenBox
local found = false
local player = script.Parent.Parent

while wait(1) do
    for i, v in pairs(testingRegionsBoxes:GetChildren()) do
        found = false
        player:SetAttribute("Zone", "none")

        local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
        local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())

        for _, part in pairs(parts) do
            if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
                found = true
                break
            else
                found = false
            end
        end
        if found == true then
            print(v)
            player:SetAttribute("Zone", v.Name) --here is the issue, instead of making it "redbox" it will make it "none" and will only work if the box is "greenBox"
        end
    end
end

I also have screenshots of the instance as well as proof that it can actually read the object, but it refuses to set it as the value of an attribute. I'll post the output below. Thanks for reading

0
https://cdn.discordapp.com/attachments/723045193292447768/841890678912843776/unknown.png not working screenshot, zone attribute is "none" instead of "redBox" indefiniteOptimist 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
local parts = game.Workspace:FindPartsInRegion3WithWhiteList

Spot something?

0
nothing in particular no indefiniteOptimist 0 — 2y
0
FindPartsInRegion3WithWhiteList GiantDefender427 0 — 2y
Ad

Answer this question