Hello I tried to make a Placement script where you can place objects by following a tutorial on youtube but I failed to do so. There are no errors appearing but still it does not seem to be working. When you click the Button it places the object but you cannot move it around or rotate as it showed in the tutorial.
The script inside of the UI:
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
local Frame = script.Parent:WaitForChild("Frame")
local UserInputService = 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 RotationAmount = 0
local PreviewObject = ObjectFolder: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.CanColide = false
end
end
UserInputService.InputBegan:Connect(function(Key, GameProcessed)
if not GameProcessed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
while RotatingObject == true do
wait()
RotationAmount += 2
end
end
end
end)
UserInputService.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
Mouse.TargetFilter = PreviewObject
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(RotationAmount), 0)
PreviewObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)
end
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
It is a long script that I can understand so who ever fixes it gets 10 Robux
The script inside of serverscriptservice:
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")
PlacementEvent.OnServerEvent:Connect(function(player, PreviewObject, ObjectCFrame)
local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
Object:setPrimaryPartCFrame(ObjectCFrame)
Object.Parent = game.Workspace
end)
The folders where the objects are present
Please do help me as it will be very helpful