This touch event is only detecting the characters parts and nothing else. Im not sure why here is the code. Only printing the players parts
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)
So, it’s printing the player characters’ parts because the model’s PrimaryPart is only touching a limb, so in order to print the character/player’s name you would have to do something along the lines of print(hit.Parent.Name).
I like to add an if statement such as if hit.Parent:FindFirstChild("Humanoid") ~= nil then..., just for good practice given you want to make sure you’re detecting a character.
Some more explanation would also be helpful, though like Shawn said.
Im not trying to do anything to the player, im trying to detect if two parts collide with each other. But its only detecting the players characters parts.
No im not trying to detect the player, im trying to detect other parts in workspace. its touching them but somehow not detecting them. This is the first time ive ever encountered this issue,
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)
Maybe you should take a look at your conditionals. Are you sure you want the thing the player is colliding with to have the same name as the model? Maybe you meant to do a “~=” operator?
Well right now all im concerned about is the printing, because right after the touched event fires its only detecting the player. There are no conditionals at that point.
The thing is im not trying to deal with the character. I dont want it to only detect the character, i want it to detect workspace parts. I have no clue why this is happening either it was working fine on my other scripts the other day