Hi, So I was making a Plot system For My farming game and I ran into a Problem
Players Can place Seeds inside each other… If you don’t understand please tell me because English isn’t my main language Any help is appreciated.
Here is the Code for Placing the Seed (Client-Side)
local Player = game.Players.LocalPlayer
local CarrotTool = script.Parent
local Mouse = Player:GetMouse()
local Placing = false
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MaterialSeedsFolder = ReplicatedStorage:WaitForChild("Seeds")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local PlotSystemBuildPart = MaterialSeedsFolder:WaitForChild(CarrotTool.Name):Clone()
PlotSystemBuildPart.Parent = nil
PlotSystemBuildPart.Anchored = true
PlotSystemBuildPart.CanCollide = true
PlotSystemBuildPart.Transparency = .4
CarrotTool.Equipped:Connect(function()
PlotSystemBuildPart.Parent = game.Workspace
Placing = true
end)
CarrotTool.Unequipped:Connect(function()
PlotSystemBuildPart.Parent = nil
Placing = false
end)
Mouse.Move:Connect(function()
if Placing == true then
local RayCastResult = workspace:Raycast(Mouse.Hit.Position + Vector3.new(0,150,0),Vector3.new(0,-250,0))
if RayCastResult ~= nil then
if RayCastResult.Instance.Name == "PlotSpace" and RayCastResult.Instance.Parent:WaitForChild("PlayerOwns").Value == Player.Name then
PlotSystemBuildPart.Position = RayCastResult.Instance.Position + Vector3.new(0,PlotSystemBuildPart.Size.Y/1,0)
end
end
end
end)
CarrotTool.Activated:Connect(function()
RemoteEvents.PlacingEvent:FireServer(CarrotTool, PlotSystemBuildPart.Position)
end)
local foundCharacter = game:GetService("Players"):GetPlayerFromCharacter(RayCastResult.Instance) --// Might need to be Instance.Parent
if RayCastResult.Instance.Name == "PlotSpace" and RayCastResult.Instance.Parent:WaitForChild("PlayerOwns").Value == Player.Name and not foundCharacter then
PlotSystemBuildPart.Position = RayCastResult.Instance.Position + Vector3.new(0,PlotSystemBuildPart.Size.Y/1,0)
end
I think you don’t understand, I meant like a Person Placing Objects inside of Objects
Like Blocks Inside of blocks
here is the game
Once you join you will teleport to the Plot
In there buy some Seeds from the shop and Place them you will see that You can place objects in objects https://www.roblox.com/games/9954215671/Harvesting-Simulator-PRE-ALPHA
I think the easiest way to prevent this sort of behavior would be to add a BoolValue to every location that the player can plant crops on. When they add a crop to a tile, set the BoolValue's value to true. When they harvest a crop, set it to false.
You would then add an additional check at this if statement to see if the BoolValue's value is set to false.
if RayCastResult.Instance.Name == "PlotSpace" and RayCastResult.Instance.Parent:WaitForChild("PlayerOwns").Value == Player.Name then
PlotSystemBuildPart.Position = RayCastResult.Instance.Position + Vector3.new(0,PlotSystemBuildPart.Size.Y/1,0)
end
First of all, theres actually a problem with the question your asking. You should be asking for effective techniques to detect when a 3d vector (your mouse pos in 3d space) exists inside another 3d vector + position. Second of all this is all on the client side, therefore anyone with a logic injector (like synapse) could ignore the raycast and manipulate what passes through [PlacingEvent]. Raycast is kind of an expensive operation to run on the server. You should replace the vector your passing with 2 floats. A desired x and a desired y, then have the server check if the values exist in your [plot]. As for what you are trying to accomplish, everything you need should be in here. Hope it helps