[Solved] Roblox broke my script?

  1. What do you want to achieve? I want to make a button that removes a model inside the player.
  2. What is the issue? When stepped on it does nothing. In the past the script worked without a problem at all.
  3. What solutions have you tried so far? I tried to re-write the script and add print or warn. The script works however nothing happens.
function onTouched(hit) 
	-- get all the parts in the player model
	local d = hit.Parent:GetDescendants() 
	-- loop all the parts in the model (variable d)
	for i, v in pairs(d) do
		-- check if the name is Bandages
		if v.Name == "Bandages" then
			-- if so delete it
			v:Destroy()
			script.Parent.Touched:connect(onTouched)
		end
	end
end 

Conclusion: If you feel like Roblox broke your script, check if there isn’t missing any sentance. I do feel embarassed for not checking the script properly.

function onTouched(hit) 
	-- get all the parts in the player model
	local d = hit.Parent:GetDescendants() 
	-- loop all the parts in the model (variable d)
	for i, v in pairs(d) do
		-- check if the name is Bandages
		if v.Name == "Bandages" then
			-- if so delete it
			v:Destroy()
		end
	end
end

script.Parent.Touched:connect(onTouched)

I would suggest doing checks to see if the toucher was a player.

1 Like

Ah, I was blind. The last line was missing. Thank you.

The Bandages is an accessory, right? Since if it isn’t, you can easily put it inside of an accessory. Name the Bandages “Handle” instead, make an attachment the name of the attachment in the character you want it to be connected to (look up R6 or R15 attachment rig on the toolbox) and then drag the accessory inside the character. You can then select the attachment in the Bandages, activate the move tool (the default move tool for the attachment is broken), and move it the opposite way you want to move the accessory.

Edit: even if it isn’t an accessory but works, this would work better anyway and clean up the game