Script Doesn't Work

I want to print “hi” when a player is touching the part with an equipped tool and activated
the activated part doesn’t work and i don’t know why thanks for those who help i appreciate it a lot

1th option i tried:
image

2th option i tried:
image

server side:

Sometimes when I try to use the .Activated event on Roblox Studio it doesn’t work, but should work on the roblox client. Have you tried checking on an actual game?

You are making all your connections to the functions in the wrong way for instance the server script you have will repeatedly make connections to all the parts over and over if that ever does fire the clients its going to be many many times at once

your activated should be connected to directly in the base tool script same with equipped

1 Like

no i didn’t tried it out of the studio, is it a common problem with the “.Activated”?

I don’t know if it’s common, but I can tell you in many instances it happened to me on my projects.

Try this directly in your tool script you will see what i mean

local Tool = script.Parent


Tool.Activated:Connect(function()
	print('Hi i have been Activated')
end)

Tool.Equipped:Connect(function()
	print('Hi i have been Equipped')
end)

Tool.Unequipped:Connect(function()
	print('Hi i have been Unequipped')
end)

Also you should remove the while loop you have in your server script or atleast put the for loop thats making connections outside of it

when the player standing on the part and has an equipped tool and clicks it while he is on the part it should print that phrase


it says that it must be equipped

“Also you should remove the while loop you have in your server script or at least put the for loop thats making connections outside of it”

i want the game check when player is standing on that specific part that part’s parent is the folder
i mean whats inside the folder should be acceptable for touch and do the event

right that means you select the tool at the bottom of the screen which then puts it into the character which means the tool is equipped at that point

the activated happens when the player clicks the mouse

the connections to both the activate and the equipped need to be done in the base tool if not you will need to disconnection the connections

your above code shows you connected functions when remote events fire multi times and connections inside connected functions

This is really all you need in the tool script it will set an attribute when the tool is being activated and held down when they let off mouse it will remove the activated attribute

local Tool = script.Parent


Tool.Activated:Connect(function() -- this will add the activated attribute so you can check on server if tool is activated
	print('Hi i have been Activated')
	Tool:SetAttribute('Activated', true)
end)

Tool.Deactivated:Connect(function()   -- this will remove the activated attribute
	print('Hi i have been Deactivated')
	Tool:SetAttribute('Activated', nil)
end)

now on the server in the touched function get the Tool from the character and do

if Tool:GetAttribute('Activated') then
	--- do something here their tool is active
end

still don’t work

do you see the printouts from that when you click while tool is equip?

also your remote event is setup wrong you don’t do the equip connection in there like that its is done in the base script for the tool same as i posted above

no need for it in the event…

then if you leave the activated it might work if all else is good on server side

i don’t get prints in that way, but when i leave only the equiped part its printing

as i explained above i want only certain part will ablet to be fired by event

when i stand on the part and i activate the tool on it, it will do something

but while i am standing on that part

this part here would go in the server script in the tool the part on that post at bottom is where you check on the server in the touched event then you fire the clients if that attribute is on that tool
Server script in tool

this is probably what you need on your server side like i explaining in the above post.

for i, v, in ipairs(mopablefolder:GetChildren()) do  -- you only loop through these once no need for while loop like i said above
	v.Touched:Connect(function(hit)   -- make a connection to touched function for this part
		if hit.Parent:FindFirstChild('Humanoid') then  -- see if humanoid/character
			local Tool = hit.Parent:FindFirstChild('TOOL NAME GOES HERE')  -- make sure to change to your tools name  -- this gets the tool if they player has it equipped..
			if Tool then  -- the tool is in the character
				if Tool:GetAttribute('Activated') then  --  if this attribute is there then the tool is currently active 
					Event:FireAllClients(v)  -- so fire all clients
				end
			end
		end
	end)
end

now on your client side you will need a local script somewhere that has the event setup in it so when the server fires it will run the code you want

tool main:
image

server:

still don’t work i did what you said

1 Like

is your tool main script a server or local script?

try doing print on the attribute
also might want to set the mop as a tool variable and print it make sure it sees it right

local script, and where put the attribute and the print?