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

Why region detector doesn't work in game?[UNANSWERED]

Asked by
npott13 23
7 years ago
Edited 7 years ago

How do i convert this to FE? I got a brick inside the model that i could drag, it's supposed to be the main detector of parts so when a player placed the model on a area where there is parts it will not allow it.

This is the brick detector script.

_G.detected = nil 
while wait() do

    local d = script.Parent
    local pos = d.Position
    local size = d.Size/2
    local reg = Region3.new(pos - size, pos + size)
    local p = script.Parent.Parent
    local ignore = {workspace.Baseplate,d,p}
    local n = workspace:FindPartsInRegion3WithIgnoreList(reg,ignore,100)
    if #n <= 0 then

        _G.detected = false
    else


    _G.detected = true 
    _G.down = true
        end
    end

Then on a player starterpack i got localscript for the main dragging, this is just part of it where assuming a player is dragging the model and released the button, we know that the brick detector will set detected to true if there is part so it'll not allow it, if detected is true then model will remain as mouse target.

mouse.Button1Up:connect(function()

    pcall(function()
    if (player.Character.Torso.Position - mouse.Target.Position).magnitude >= 100 or _G.detected == true then
    _G.down = true
    _G.target = mouse.Target.Parent

    script.Parent.Parent.PlayerGui.Warning.Enabled = true
    _G.selectionBox = Instance.new("SelectionBox")
_G.selectionBox.Adornee = mouse.Target.Parent
_G.selectionBox.Color3 = Color3.fromRGB(255,0,0)

_G.selectionBox.Parent = camera

    else

    _G.selectionBox.Adornee = nil

    _G.selectionBox.Parent = nil
    mouse.TargetFilter = nil
    _G.down = false
    _G.target = nil
    script.Parent.Parent.PlayerGui.Warning.Enabled = false
    _G.selectionBox.Color3 = nil

    end

end)    
end)

THE PROBLEM

the region detector doesn't work in-game only on studio. I can't think of any reason why maybe converting the detector script to F.E will fix but i don't know how..

0
I'm pretty sure the problem is that one script is running on the server and the other is running on the client (LocalScript). and you're using global variables. Overscores 381 — 7y
0
So, i'll need to use module instead of global variables, but i'm not sure how to fix the thing where the other runs on localscript and server. npott13 23 — 7y
0
Don't use _G lol. RubenKan 3615 — 7y
0
can you give me example how to not use global variable npott13 23 — 7y

Answer this question