Tool.Activated Not firing at all

I made this code, but it only prints “Working”, but when activated it does not print “Activated” like it’s supposed to. I have restarted studio too, and it note that the code does not work in the normal roblox app either. The script randomly stopped working. It also does not have any errors in output when activated.

script:

local Tool = script.Parent
print("Working")

local function ActivateTool()
	print("Activated")
	local Char = script.Parent.Parent
	local Player = game.Players:FindFirstChild(Char.Name)
	
	if workspace:FindFirstChild(Player.Name .. " Vehicle " ) then

	else
		local Truck = game.ServerStorage.SpawnableCars:FindFirstChild(script.Parent.Truck.Value):Clone()
		Truck.Name = Player.Name .. " Vehicle " --.. script.Parent.ToolName.Value
		Truck.Parent = workspace
		local CFrame = script.Parent.Spawn.CFrame
		Truck:SetPrimaryPartCFrame(CFrame)
		Truck:MakeJoints()
	end
end

script.Parent.Activated:Connect(ActivateTool)
1 Like

Have you tried this

local Tool = script.Parent


Tool.Activated:Connect(function() -- this
   print("test")
   local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- this

  if workspace:FindFirstChild(Player.Name .. " Vehicle " ) then

	else
		local Truck = game.ServerStorage.SpawnableCars:FindFirstChild(script.Parent.Truck.Value):Clone()
		Truck.Name = Player.Name .. " Vehicle " --.. script.Parent.ToolName.Value
		Truck.Parent = workspace
		local CFrame = script.Parent.Spawn.CFrame
		Truck:SetPrimaryPartCFrame(CFrame)
		Truck:MakeJoints()
	end
end)

Yes, thats what the code was at first so i changed it still did nothing

Is the tool enabled? That could be the problem.

It is enabled
image

Check if script.Parent is the Tool itself and not a random Object

Check if your Script is Enabled

Check your Spelling, Is it spelled correctly?

I checked and it was fine my script was enabled and script.parent was the tool

Your script is working! The problem is that there’s nothing in your if statement.

Tool.Activated:Connect(function() -- this
   print("test")
   local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- this

  if workspace:FindFirstChild(Player.Name .. " Vehicle " ) then
-- What's happening here?
	else
		local Truck = game.ServerStorage.SpawnableCars:FindFirstChild(script.Parent.Truck.Value):Clone()
		Truck.Name = Player.Name .. " Vehicle " --.. script.Parent.ToolName.Value
		Truck.Parent = workspace
		local CFrame = script.Parent.Spawn.CFrame
		Truck:SetPrimaryPartCFrame(CFrame)
		Truck:MakeJoints()
	end
end)

The script works just fine for me. Either you have the script in the wrong place, studio’s bugging, or maybe you aren’t activating the tool (reminder that the .Activated event only fires when the player clicks while the tool is equipped.)

Well that can’t be it because the if statement was there since the start and then it randomly stopped working

Hmm i’ll try restarting my computer Nvermind i dont think it will work because it doesnt work in-game (like the actual roblox app) for my friends or me

Also the script is here
image

Would it be okay if you sent a RBX file of that tool since it might make debugging easier (thought you don’t have to if you don’t want to)

carsar.rbxm (19.4 KB)

(spawnablecars go in serverstorage)

Hmmm, that’s strange. It works perfectly fine for me! I really don’t know what’s happening on your side. Is this what it’s supposed to do?

Yes that’s it! but i still cant understand whats happening with my game. Its pretty big and has lots of unanchored parts so I don’t know if the game size or lag could be the problem though

Yeah, that could be the problem. Sorry I couldn’t be of much help. Does the script like not output anything at all (other than “working”)

Yea it only outputs “working”" i just tested the tool in a baseplate and it worked there too. I think it is my game thats the problem ill try to fix that Edit: fixed it! turns out it was a script, thanks for helping though

2 Likes

I have the same problem as you, can you explain more how to fix it please?

I had a grab script overriding the mousebutton1 function for tools

1 Like