Hello,
The following code spawns bricks on the ground as a player travels:
local PhysicsService = game:GetService("PhysicsService")
local Bin = script.Parent
game:GetService("RunService").Heartbeat:Connect(function()
if Bin then
local COLOR
local MATERIAL
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Bin, workspace.NPC, workspace.PLAYERS}
local origin,direction = Bin.CFrame.p,Vector3.new(0,-1,0).unit*10
local raycastResult = workspace:Raycast(origin,direction,raycastParams)
if raycastResult then
local HIT = raycastResult.Instance
COLOR = HIT.Color
MATERIAL = HIT.Material
else
COLOR = Color3.fromRGB(160,95,53)
MATERIAL = "Slate"
end
local A = Instance.new("Part")
PhysicsService:SetPartCollisionGroup(A,"CLOUDS")
A.Parent = workspace
A.Anchored = true
A.Color = COLOR
A.Material = MATERIAL
A.Size = Vector3.new(2,2,2)
A.CFrame = CFrame.new(raycastResult.Position.X,raycastResult.Position.Y,raycastResult.Position.Z)
A.CFrame = A.CFrame*CFrame.Angles(math.rad(math.random(30,90)),math.rad(math.random(30,90)),math.rad(math.random(30,90)))
game.Debris:AddItem(A,1)
end
end)
The code itself works fine however it’s what the client sees that’s the problem. When this is performed from a server script, my client sees what is shown below. You’ll see the bricks are spawned behind the player. I attempted this with two clients and one client saw the bricks spawn behind the player and the other actually saw them spawn ahead of the player…
I transferred this code into a LocalScript, and as I figured it looked perfect on the client, however doing this would prevent other players from seeing it.
The overall issue is that I would like to make the bricks spawn as seen in the local script demonstration, but replicate across all clients and spawn bricks into the server that are interact-able. Any suggestions would be appreciated!
Thanks,
Romul