I’m making a sandbox game (with planets and stuff) but for some reason when I try to place any objects, the object won’t follow the mouse. It just stays in its original position.
You need to give more context. Pictures of your scripts etc.
You’re probably not setting the objects position properly.
Server Script:
local PlacementEvent = game:GetService("ReplicatedStorage"):WaitForChild("PlacementEvent")
local ObjectFolder = PlacementEvent.Parent.Objects
PlacementEvent.OnServerEvent:Connect(function(plr,PreviewObject, ObjectCFrame)
local object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
object:SetPrimaryPartCFrame(ObjectCFrame)
object.Parent = game.Workspace
end)
Local Script (Inside ScreenGui)
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjecFolder = game.ReplicatedStorage:WaitForChild("Objects")
local plr = game.Players.LocalPlayer
local char = workspace:WaitForChild(plr.Name)
local mouse = plr:GetMouse()
local Frame = script.Parent:WaitForChild("ScrollingFrame")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local PlacingObject = false
local RotatingObject = false
for i, Button in pairs(Frame:GetChildren()) do
if Button:IsA("TextButton") then
Button.MouseButton1Click:Connect(function()
if PlacingObject == false then
PlacingObject = true
Frame.Visible = false
local RotAmount = 0
local previewObject = ObjecFolder:FindFirstChild(Button.Name):Clone()
previewObject.Parent = game.Workspace
for i, Parts in pairs(previewObject:GetDescendants()) do
if Parts:IsA("BasePart") then
Parts.Transparency = 0.5
Parts.CanCollide = false
end
end
UIS.InputBegan:Connect(function(key,gameProcessed)
if not gameProcessed then
if key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
while RotatingObject == true do
wait()
RotAmount += 2
end
end
end
end)
UIS.InputEnded:Connect(function(key)
if key.KeyCode == "R" then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
mouse.TargetFilter = previewObject
end
if previewObject:FindFirstChild("MainPart")then
local ObjectCFrame = CFrame.new(mouse.Hit.Position.X, mouse.Hit.Position.Y + previewObject.PrimaryPart.Size.Y /2,
mouse.Hit.Position.Z)
local oBjectAngles = CFrame.Angles(0, math.rad(RotAmount), 0)
previewObject:SetPrimaryPartCFrame(ObjectCFrame*oBjectAngles)
end
end)
mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(previewObject.Name, previewObject.PrimaryPart.CFrame)
Frame.Visible = true
previewObject:Destroy()
end
end)
end
end)
end
end
Is the issue displaying the previewobject or actually placing the object? Ive used the same code in one of my games without issue.
Video:
As in i followed the same tutorial
I think i know. The mouse is never hovering over anything to get the position of!
Its hovering over a very “hard to see” platform
I kinda rushed the tutorial. are the parts supposed to be anchored?
I suggest slowly working through the tutorial then, and make sure you understand it. I cant remember but i would think so.
Do you have a part called MainPart in your planets?
And have you tried moving closer to your “platform”? Just to see if you can place
Are they REQUIRED to be called MainPart? I just added a primary part (cause some estupido forgot to watch the start
Yup, its required. filling out my requirement here
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
mouse.TargetFilter = previewObject
end
if previewObject:FindFirstChild("MainPart")then
--RIGHT HERE its looking for a part called MainPart
bruh it worked thanks
(filling required)
Noice, glad i could help ya out