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

How do I get this script to recognize between the different parts associated with region?

Asked by 3 years ago
Edited 3 years ago

So I've been trying to script a pretty standard plot system for my game that assigns one of the 25 plots to you upon spawning and is able to recognize its you when you enter the area of the plot. So far I've gotten it to assign a plot to the player by making the player the value of an ObjectValue within the part, however I'm still struggling to have it recognize it's the player due to the last few lines of code. To make it recognize the player I've created a part above each of the plots and used the regions3 service on the blocks above the plots so anyone touching the block will be detected and I can execute the script if they own the plot. It recognizes that it's a player but I'm stumped trying to figure out how to make it recognize who owns which plot (it executes the script as though the person touching the block owns the plot below even if they don't). Was wondering if I could get some help on this one (explanation on how preferable though so I can learn from it).

(if your wondering what the plot variable means see the script below this one)

SCRIPT:

game:GetService("ReplicatedFirst")
wait(5)
local plotService = require(game.ReplicatedStorage.PlotService)
local plot = plotService:GetPlot(game.Players.LocalPlayer)
print(plot)
local PlotList = game.Workspace.Plots
local Detector = game.Workspace:WaitForChild("PlotDetectors")
local found = false

while wait(1) do
    found = false
    for i, v in pairs(Detector:GetChildren()) do 
        local region = Region3.new(v.Position - v.Size/2, v.Position + v.Size/2)
        local part = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())

        for _, parts in pairs(part) do
            if parts:FindFirstAncestor(game.Players.LocalPlayer.Name) then
                found = true
                break
            else
                found = false
            end
        end
        if found == true then
            print(plot.Occupant.Value)
            print(game.Players.LocalPlayer.Name)
            if plot.Occupant.Value == game.Players.LocalPlayer then --This is the part I have troube with, as it thinks that the value is the same as 
                print("You own the plate!")--executes functions i have yet to put in place, will do once figuring out the previous segment
            else 
                print("not your plate") --nothing happens
            end

        end
    end
end

SECOND SCRIPT:

local PlotService = {}

local plots = game.Workspace.Plots
function PlotService:GetPlot(player)
    for i, plot in pairs(plots:GetChildren()) do
        if plot.Occupant.Value == player then

            return plot

        end
    end

end

return PlotService

I believe the game thinks they are the same because the plotservice is only getting the plot that the player owns, so when the if statement runs for it being the same value then it instantly thinks it is regardless of which region it touched, but I'm also not sure how I would go about fixing this, I'd appreciate if I could get some help though. (sorry if the explanations were too long or anything was confusing, this is my first time using this site)

0
not sure why the inlining came out like that but ok... TheNotableGnome 0 — 3y
0
would you mind fixing the inlining? it would help me in answering your question :) NinjaManChase 226 — 3y
0
Is there any specific way to increase the lines in the inlining? the inline symbols (`) aren't affecting it for some reason, or am I just doing it wrong? TheNotableGnome 0 — 3y
0
use the lua code option instead, inline is for code placed inside of text. Benbebop 1049 — 3y
0
alright should be fixed now TheNotableGnome 0 — 3y

Answer this question