Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this work whenever the part touiches another part? [Unanswered]

So I have this part that is created with this script

local Player = game.Players.localPlayer
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:wait()
	plr.Character:WaitForChild("Torso")
	local torso = plr.Character.Torso
	local part = Instance.new("Part", game.Workspace)
	part.Transparency = 1
	part.CanCollide = false
	part.Size = Vector3.new(7,7,7)
	game.Lighting.Find:Clone().Parent = part
	part:FindFirstChild("Find").Disabled = false
	part.Anchored = true
while wait(0.025) do
	part.CFrame = CFrame.new(torso.Position)

end
end)

and whenever the part touches another part I want it this script (located in the part created above) to fire its function

while wait(0.1) do
script.Parent.Touched:connect(function(hit)
	local found = hit:FindFirstChild("ItemName")
		if found then
			print(found.Parent.Name)
	end
end)
end

for some reason it doesn't work and its not the collision either

5 comments

3
  1. Why is your event in a loop? 2)Why are you referencing localplayer(incorrectly)? It should be a normal script 3) Leave the script enabled. It won't run in Lighting.
0

"Why are you referencing localplayer(incorrectly)?" I think that should be a statement rather than a question lol

0

the 2nd script has the error.... the first script is just the understanding of how the 2nd script works

0

Overall your code just doesn't make any sense. What are you trying to accomplish here?

0

It makes perfect since if the part created in the first script touches another part check the touched part for a Object c alled ItemName if that object exists then print the objects parent's name

1 answer

✓ Accepted answer

First off, remove the local player line, and move the first script into a normal script, and move it to server script service,

Then remove the while wait loop, it's useless, and inefficient.

Finally, make sure ItemName is actually a child of the correct part, and that it's capitalization is correct.

This discussion is preserved as it was. New answers, comments, and votes are closed.