Im trying to create a system that allows the player to place for a example a Cup on a table.
But keep in mind theres a previous script that changes its name because of a Cafe thing (too long to explain).
ALSO IMPORTANT: im also struggling with making it so the tool can only be placed on specific parts like only on tables or a counter.
A dev told me to add a bool value and to add a code but for now I’m trying to figure out how to place it without bool
Ive watched a video on placement system but they dont seem to work. Also its not rlly what im looking for thats why im here
im in need of help
Notes for the code:
Folder named Objects in replicated storage inside is what u want to be placed down
This is ONE of the code that i had to create based off the video:
Second code is under it. THIS is a local script in StarterCharacterScripts
local CS = game:GetService("CollectionService")
local TS = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local PlaceObject = RS:WaitForChild("PlaceObject")
local TI = TweenInfo.new(.4)
local objects = RS:WaitForChild("Objects")
local temporaryObjects = workspace:WaitForChild("TemporaryObjects")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = script.Parent
local currentObject = nil
local debounce = false
local function move()
local posX = math.floor(mouse.Hit.X)
local posZ = math.floor(mouse.Hit.Z)
local orientationY = currentObject.PrimaryPart.Orientation.Y
debounce = true
local Tween = TS:Create(currentObject.PrimaryPart, TI
{CFrame = CFrame.new(posX, currentObject.PrimaryPart.Position.Y, posZ) * CFrame.Angles(0, math.rad(orientationY), 0)})
Tween:Play()
Tween.Completed:Wait()
debounce = false
end
local function weld()
debounce = true
for objs, obj in pairs(currentObject:GetDescendants()) do
if obj:IsA("BasePart") and obj ~= currentObject.PrimaryPart then
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Part0 = obj
weldConstraint.Part1 = currentObject.PrimaryPart
weldConstraint.Parent = obj
obj.Anchored = false
obj.CanCollide = false
end
end
mouse.TargetFilter = currentObject
debounce = false
currentObject.PrimaryPart.CanCollide = false
return
end
local function init()
local hitbox = Instance.new("Part")
local orientation, size = currentObject:GetBoundingBox()
hitbox.Size = size
hitbox.CFrame = orientation
hitbox.Transparency = 1
hitbox.Parent = currentObject
hitbox.Anchored = true
currentObject.PrimaryPart = hitbox
weld()
return
end
local function place(tool)
PlaceObject:FireServer(currentObject.Name, currentObject.PrimaryPart.Position.X, currentObject.PrimaryPart.Position.Z)
temporaryObjects:ClearAllChildren()
tool:Destroy
end
local function checkForEquipped()
for index, tool in pairs(CS:GetTagged("PlacementObjects")) do
local moveConnection = nil
tool.Equipped:Connect(function()
local foundObject = objects:FindFirstChild(tool.Name)
if foundObject then
currentObject = foundObject:Clone()
currentObject.Parent = temporaryObjects
init()
moveConnection = mouse.Move:Connect(move)
move()
tool.Activated:Connect(function()
if moveConnection ~= nil then
moveConnection:Disconnect()
moveConnection = nil
place(tool)
end
end)
end
end)
tool.Unequipped:Connect(function()
if moveConnection ~= nil then
moveConnection:Disconnect()
moveConnection = nil
temporaryObjects:ClearAllChildren()
end
end)
end
end
checkForEquipped()
This is a normal script located in ServerScriptService
SECOND SCRIPT:
local RS = game:GetService("ReplicatedStorage")
local placeObject = RS:WaitForChild("PlaceObject")
local placedObjects = workspace:WaitForChild("PlacedObjects")
local objects = RS:WaitForChild("Objects")
local function weld(currentObj)
for objs, obj in pairs(currentObj:GetDescendants()) do
if obj: IsA("BasePart") and obj ~= currentObj.PrimaryPart then
local weld = Instance.new("WeldConstraint")
weld.Part0 = obj
weld.Part1 = currentObj.PrimaryPart
weld.Parent = obj
obj.Anchored = false
obj.CanCollide = false
end
end
currentObj.PrimaryPart.CanCollide = false
return
end
local function init(obj)
local hitbox = Instance.new("Part")
local orientation, size = obj:GetBoundingBox()
hitbox.Size = size
hitbox.CFrame = orientation
hitbox.Transparency = 1
hitbox.Parent = obj
hitbox.Anchored = true
obj.PrimaryPart = hitbox
weld(obj)
return
end
local function place(obj, posX, posZ)
local orientation = obj.PrimaryPart.Orientation.Y
obj:SetPrimaryPartCFrame(CFrame.new(posX, obj.PrimaryPart.Position.Y, posZ) * CFrame.Angles(0, math.rad(orientationY), 0))
obj.PrimaryPart.CanCollide = true
return
end
placeObject.OnServerEvent:Connect(function(plr, objectName, posX, posZ)
local foundObject = objects:FindFirstChild(objectName)
if foundObject then
local clonedObject = foundObject:Clone()
init(clonedObject)
place(clonedObject, posX, posZ)
clonedObject.Parent = placeObjects
end
end)