Part Detector, won't detect copied Tool but detect the one from StarterPack

Hello,
I’m currently making a ticket door for the Train Station of my Tokyo showcase, the problem is:
The ticket from the StarterPack open the door, but the one copied from the GUI who give you the ticket don’t, this is the same tools with the same name
I don’t understand the issue, if someone can help me, I’ll really appreciate it!

1 Like

Is the tool cloned to the backpack?

Yes, it’s copied to player backpack. @mandude325

local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local ticket = script["Train Ticket"]
script.Parent.Activated:Connect(function()
local TCP = ticket:Clone() 
TCP.Parent = plr.Backpack
script.Parent.Parent.Parent.Enabled = false
end)

Can you provide the script that detects the tool?

local stun = false
local door1 = script.Parent.Parent.swingdoor
local door2 = script.Parent.Parent.swingdoor2
local pos1 = door1.CFrame
local pos2 = door2.CFrame
local width1 = (door1.Size.X/2)+0.5
local width2 = (door2.Size.X/2)+0.5
local player = game:GetService("Players")
function clickCheck(h)
print(h.Parent.name)
if h.Parent.name == "Train Ticket" then
		if stun == false then
			stun = true
			for i = 1,18 do
				door1.CFrame = pos1*CFrame.new(width1*math.cos(math.rad(5*i))-width1,0,width1*math.sin(math.rad(-5*i)))
				door1.CFrame = door1.CFrame*CFrame.Angles(0,math.rad(5*i),0)
			    door2.CFrame = pos2*CFrame.new(width2*math.cos(math.rad(5*i))-width2,0,width2*math.sin(math.rad(-5*i)))
				door2.CFrame = door2.CFrame*CFrame.Angles(0,math.rad(5*i),0)
				wait(0)
			end
			wait(1)
			for i = 1,18 do
				door1.CFrame = pos1*CFrame.new(width1*math.cos(math.rad(5*(18-i)))-width1,0,width1*math.sin(math.rad(-5*(18-i))))
				door1.CFrame = door1.CFrame*CFrame.Angles(0,math.rad(5*(18-i)),0)
				door2.CFrame = pos2*CFrame.new(width2*math.cos(math.rad(5*(18-i)))-width2,0,width2*math.sin(math.rad(-5*(18-i))))
				door2.CFrame = door2.CFrame*CFrame.Angles(0,math.rad(5*(18-i)),0)
				wait(0)
			end
		end
		stun = false
end
end
script.Parent.Touched:Connect(clickCheck)

Okay can you tell me is the script that clones the tool a local script?

Judging by the use of local player I would say yes

You can do this instead:

local FindTool = Character:FindFirstChild('ToolName') or Backpack:FindFirstChild('ToolName')
if FindTool then
   print('Tool has been found in character/backpack, and will not duplicate.')
   return
end
-- give players the tool here.

I call this type of check an inline expression, and it is very efficient.

EDIT:
It should be h.Parent.Name, not .name. After quickly reading through it all, I assume that’s the only issue I can see of the provided script.

If you clone this tool with a localscript (and the tool is controlled by a serverscript), the server will not know that the tool’s parent has changed due to the client doing it all, hence why it won’t work.

  • As someone stated above: I recommend changing that to a server script.

Server scripts cannot detect local parts in this case a tool created by a local script. try changing the script that clones the tool to a server script.

@TheWiseAndGreat I can’t use a script in a GUI, so I’ve used a RemoteEvent, and used @Xueify script to identify the tools (I also used with h.Parent), still not working.

Is there any errors? (30 characters)

Regardless, have a look at this script:


local Players = game:GetService('Players')

local ToolName = 'Train Ticket'
local Debounce = false

local Part = script.Parent

local Door1 = Part.Parent.swingdoor
local Door2 = Part.Parent.swingdoor2

local Pos1 = Door1.CFrame
local Pos2 = Door2.CFrame

local width1 = (Door1.Size.X / 2) + .5
local width2 = (Door2.Size.X / 2) + .5

local function Loop(Start, Goal)
	for i = Start, Goal do
		Door1.CFrame = Pos1 * CFrame.new(width1 * math.cos(math.rad(5 * i)) - width1, 0, width1 * math.sin(math.rad(- 5 * i)))
		Door1.CFrame = Door1.CFrame * CFrame.Angles(0,math.rad(5 * i), 0)
		Door2.CFrame = Pos2 * CFrame.new(width2 * math.cos(math.rad(5 * i)) - width2, 0, width2 * math.sin(math.rad(- 5 * i)))
		Door2.CFrame = Door2.CFrame * CFrame.Angles(0,math.rad(5 * i), 0)
		wait(0)
	end
	
	wait(1)
	
	for i = Start, Goal do
		Door1.CFrame = Pos1 * CFrame.new(width1 * math.cos(math.rad(5 * (18 - i))) - width1, 0, width1 * math.sin(math.rad(- 5 * (18 - i))))
		Door1.CFrame = Door1.CFrame * CFrame.Angles(0, math.rad(5 * (18 - i)), 0)
		Door2.CFrame = Pos2 * CFrame.new(width2 * math.cos(math.rad(5 * (18 - i))) - width2, 0, width2 * math.sin(math.rad(- 5 * (18 - i))))
		Door2.CFrame = Door2.CFrame * CFrame.Angles(0, math.rad(5 * (18 - i)), 0)
		wait(0)
	end
end

Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
		local Character = Player.Character or Player.CharacterAdded:Wait()
		local Backpack = Player:FindFirstChild('Backpack')
		if Backpack then
			local FindTool = Character:FindFirstChild(ToolName) or Backpack:FindFirstChild(ToolName)
			if FindTool then
			--[[ I assume you want them to be able to activate it if they have it? --]]
				if Debounce then
					return
				end
				Debounce = true
				Loop(1, 18) -- start, goal
				wait(1) -- Not needed. Just to give it some cooldown if wanted.
				Debounce = false
			end
		end	
	end
end)
1 Like

Thanks alot, it work now, I think I probably made a mistake somewhere in the script.

In order for the h.Parent.Name to be the tool’s name, the tool would have to hit the actual part.
If your character hits it, it would return the character’s name as that is the h.Parent (userdata).

Another problem is that your ‘stun / debounce’ should have been moved up a line (above an end), otherwise it would keep spamming.

I keep that in mind, thanks a lot for your help, I was stuck on it since 3 hours.

You’re welcome.
(30 characters)