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)
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
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)