I’m trying to make a system where you merge things together and it deletes the models and spawns in the next but when Im doing the touched event its only detecting the characters body parts
local model = game.Workspace.boat1
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
model.PrimaryPart = model["Meshes/boat1_Cube"]
local isDragging = false
local highlight = nil
local MergeEvent = game.Workspace:FindFirstChild("MergeEvent")
if not MergeEvent then
MergeEvent = Instance.new("RemoteEvent")
MergeEvent.Name = "MergeEvent"
MergeEvent.Parent = game.Workspace
end
local function onInput(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseMovement then
local hit = game:GetService("Players").LocalPlayer:GetMouse().Target
if hit and hit:IsDescendantOf(model) then
if not highlight then
highlight = game.ReplicatedStorage.MergingSystemMain.Highlight:Clone()
highlight.Parent = model
end
else
if highlight then
highlight:Destroy()
highlight = nil
end
end
if isDragging then
local mousePosition = input.Position
local ray = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y)
local worldPosition = ray.Origin + ray.Direction * ((-0.9 * ray.Origin.Y) / ray.Direction.Y)
model:SetPrimaryPartCFrame(CFrame.new(worldPosition))
end
end
end
local function onInputEnded(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isDragging = false
end
end
local function onInputBegan(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouseHit = game:GetService("Players").LocalPlayer:GetMouse()
local hitPart = mouseHit.Target
if hitPart and hitPart:IsDescendantOf(model) then
isDragging = true
UserInputService.InputChanged:Connect(onInput)
UserInputService.InputEnded:Connect(onInputEnded)
end
end
end
model.PrimaryPart.Touched:Connect(function(hit)
print(hit.Name)
if hit.Parent and hit.Parent.Name == model.Name then
MergeEvent:FireServer(hit.Parent, model)
end
end)
UserInputService.InputBegan:Connect(onInputBegan)