Hello everyone, I am currently working on my placement module but I have encountered a problem. The title explains it all. Tell me if I need to add more info.
Additional Info:
I have tried to un-anchor it (and weld it) and anchor it → no result
I have created by making a server placement and locally place it → no result
The part I want to collide is not a primary part
Here is my script:
local p = script.Parent
print("called") --this works perfectly
script.Parent.Touched:Connect(function(part) --this doesn't get called
if part.Name == "Checker" then
print("touched")--this doesn't get called
else
print("untouched")-- or this doesn't get called
end
end)
If somebody can help me find a solution or explain why this problem occurs; I would appreciate it.
I suggest putting a print after the function so you can test if it works; check if the part is anchored.
and what’s the “Checker” supposed to be?
Give us more detail and screenshots of tools or anything you use, you’re talking about unanchoring it while we don’t even know what it is, so the things I just talked about were just guesses.
script.Parent.Touched:Connect(function(part) --this doesn't get called
print("check if touched")
if part.Name == "Checker" then
print("checker touched")--this doesn't get called
else
print("other part touched")-- or this doesn't get called
end
end)
U should try setting the part’s parent to workspace. This might be a result of roblox not doing any physic based events and physics itself outside of workspace
local p = script.Parent
print("called")
script.Parent.Touched:Connect(function(part)
if part.Name == "Checker" then
print("touched")
else
print("untouched")
end
end)
The server placement script:
local re = game.ReplicatedStorage:WaitForChild("ServerPlacement")
local folder = game.Workspace
local function place(player,part, pos)
p = part:Clone()
p.Parent = folder --game.Workspace
p:SetPrimaryPartCFrame(pos)
end
re.OnServerEvent:Connect(place)
After Testing it, it seems like it only fires when i drop the checker on top of another checker. . Kinda like when you stood still on top of the part without moving, the event does not fire. The event only fires when the part that is being hit is moving.
So the part has to be moving in order for it to detect aswell.
The Touched event is only called as a result of physics movement. The way you are moving it here seems to be by manually changing the CFrame of the part. You can read more about the specifics of the Touched event here.
“This event only fires as a result of physics movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be BasePart.Anchored at the time of the collision.”
If you walked your character over the cloned parts the Touched event would fire in those scenarios.
An alternative solution to what you’re trying to do is using a Region3 when the parts position is moved. I’ll keep as much of your original code in my example as possible.
local p = script.Parent
script.Parent:GetPropertyChangedSignal("Position"):Connect(function()
local min = p.Position - p.Size / 2
local max = p.Position + p.Size / 2
local partRegion = Region3.new(min, max)
local partsInRegion = workspace:FindPartsInRegion3(partRegion)
for _, part in pairs(partsInRegion) do
if part.Name == "Checker" then
print("touched")
else
print("untouched")
end
end
end)