Local Script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local modelToPlace = game.ReplicatedStorage:WaitForChild("Raft")
local markerModel = modelToPlace:Clone()
markerModel.Parent = game.Workspace
markerModel:SetPrimaryPartCFrame(CFrame.new(0, -1000, 0))
markerModel.WoodenRaft.Transparency = 0.2
markerModel.WoodenRaft.CanCollide = false
local function roundToStuds(position)
return Vector3.new(
math.floor(position.X + 0.5),
math.floor(position.Y + 0.5),
math.floor(position.Z + 0.5)
)
end
local function updateMarker()
local rayOrigin = mouse.Hit.p + Vector3.new(0, 10, 0)
local rayDirection = Vector3.new(0, -15, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {markerModel}
raycastParams.IgnoreWater = true
local hit = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if hit and hit.Instance:IsA("BasePart") and hit.Instance.Name == "CanPlace" then
markerModel:SetPrimaryPartCFrame(CFrame.new(roundToStuds(hit.Position + Vector3.new(0, markerModel.PrimaryPart.Size.Y / 2, 0))))
else
markerModel:SetPrimaryPartCFrame(CFrame.new(0, -1000, 0))
end
end
local function placeModel()
local rayOrigin = markerModel.PrimaryPart.Position + Vector3.new(0, 10, 0)
local rayDirection = Vector3.new(0, -15, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {markerModel}
raycastParams.IgnoreWater = true
local hit = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if hit and hit.Instance:IsA("BasePart") and hit.Instance.Name == "CanPlace" then
local newModel = modelToPlace:Clone()
local placementPosition = roundToStuds(hit.Position + Vector3.new(0, newModel.PrimaryPart.Size.Y / 2, 0))
newModel:SetPrimaryPartCFrame(CFrame.new(placementPosition))
game.ReplicatedStorage.RemoteEvents.Build:FireServer(player,placementPosition,modelToPlace)
else
print("Need part CanPlace!")
end
end
mouse.Button1Down:Connect(function()
placeModel()
end)
game:GetService("RunService").RenderStepped:Connect(updateMarker)
-- there are no errors
Server Script:
local function roundToStuds(position)
return Vector3.new(
math.floor(position.X + 0.5),
math.floor(position.Y + 0.5),
math.floor(position.Z + 0.5)
)
end
local modelToPlace = game.ReplicatedStorage.Raft
game.ReplicatedStorage.RemoteEvents.Build.OnServerEvent:Connect(function(plr,placementPosition)
local newModel = modelToPlace:Clone()
newModel:SetPrimaryPartCFrame(CFrame.new(placementPosition)) -- Error here
newModel.Parent = game.Workspace
end)
Error:
Everything seems to be correct, idk what’s wrong