I'm having trouble with the GetPartsInPart detection and don't know why..?

  1. What do you want to achieve?
    I’m making a script for a wire mechanic where a wire gets spawned into the game & welded to a detector part, and I need the detector part to search for touching parts so I can see their values from there.

  2. What is the issue?
    It wasn’t working, so I went back a few steps, made a script that just spawns a part on your cursor but the test part once spawned does not get detected at all…? Any player limbs and parts previously placed in Studio before testing the game however do get detected?

  3. What solutions have you tried so far?
    I’ve tried using a few types of GetPartsinRadius and ones similiar but they all seem to not work, and checking Developer Hub all other posts are along the lines of a weapon colliding with a part & therefore using the Touched event, not being stationary while touching one another, yet even Touched event doesnt seem to work for me.

I am still pretty new to scripting/coding at all, so I have a feeling this may just be a clumsy mistake on my end. Anyone experienced enough to point out my mistake would be greatly appreciated!

My test part spawning script (in a LocalScript inside StarterCharacterScripts)

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
uis.InputBegan:Connect(function(input)
	local mouseposx,mouseposy,mouseposz = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z
	local mousetarget = mouse.Target
	if input.KeyCode == Enum.KeyCode.C then
		local block = Instance.new("Part")
		block.Size = Vector3.new(5,5,5)
		block.Parent = workspace
		block.Position = Vector3.new(mouseposx,mouseposy,mouseposz)
		block.Name = "GreySpawnedInTestPart"
	end
end)

My part detector script (in a Script inside a part in workspace)

while true do
	local partsfound = workspace:GetPartsInPart(script.Parent)
	for index, value in pairs(partsfound) do
		if value then
			print(value)
		end
	end
	wait(1)
end

As shown, the part I placed in Studio before I ran the game is detected as usual by the blue part, but the grey part I spawned in with the script ingame is being ignored???

2 Likes

You’re spawning parts locally while trying to detect them on the server end. Instantiated parts on the client are not replicated to the server, and as a result, aren’t detected by anything on the server.

2 Likes

from what i understood you said the part is only on the client, but im still not sure how i would make it on the server aswell? sorry for the late reply btw

If an instance is on the server, it is also on the client
If an instance is on the client, it is not necessarily on the server

If you want to have your part on the server “as well”, you need to create it on the server to begin with (Instance.new("Part") in a server script), as creating it on the client will make it exist only for that client.

Because you are relying on user input to position the part, you need to transmit the position data to the server to create it by using a remote event.

2 Likes

i’ll have to learn what that is to add it but also, from what i’ve read on other topics, arent RemoteEvents pretty vulnerable to exploiters?

They are only as vulnerable as you allow them to be, but regardless in this case, firing a remote to the server is likely the best approach to your problem.

Remote Events are basically what you use to transmit data between client(s) and the server.
There is a very detailed rudimentary explanation of how remote events work, and how to use them here.

1 Like

that was kinda vague but im just gonna assume in this case it would be safe to use
thanks for your help and the link though!