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

Part not being able to detect when another part touches?

The problem is the title script:

script.Parent.Touched:Connect(function(obj)
	print("Tucc")
	script.Parent.Owner.Value = game.Workspace["Legend's 2P Tycoon Kit"].Tycoons.Tycoon1.OwnerName.Value
	if obj:FindFirstChild("Value") then
		local val = obj.Value.Value
		local pFolder = game.ReplicatedStorage.Players:FindFirstChild(script.Parent.Owner.Value)
		if pFolder then
			local coins = pFolder.Coins
			coins.Value = coins.Value + val
		end
		obj:Destroy()
	end
end)

and yes, the script is a server script inside a part that has cancollide and isnt anchored. but it does detect when a player touches it. Please help!

1 answer

This code doesn't seem to have an issue, make sure your part isn't destroyed when it's needed. Here's my rewritten code.

local TouchInteractor = (script.Parent);
TouchInteractor.Touched:Connect(function(Object)
	if Object:IsA("BasePart") then
		print("TouchInteractor has been touched by a",Object.ClassName,"and is named",Object.Name)
		TouchInteractor.Owner.Value = workspace["Legend's 2P Tycoon Kit"].Tycoons.Tycoon1.OwnerName.Value
		if Object:FindFirstChild("Value") then
			local val = (Object.Value.Value);
			local pFolder = game:GetService("ReplicatedStorage")["Players"]:FindFirstChild(script.Parent.Owner.Value);
			if pFolder ~= nil then
				local Coins = pFolder["Coins"]
				Coins.Value = (Coins.Value) + (val);
			end
			Object:Destroy()
		end
	end
end)

3 comments

0

It still doesn't trigger :C

0

It still doesn't trigger :C

0

It could be an external script messing with your current script. Check the output for errors, let me know what you see.

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