Make accesory cant touch

  1. What do you want to achieve?
    I want the accesories have cant touch and cant register propetry

  2. What is the issue? Include screenshots / videos if possible!
    Problem is due to accesories not being loaded the script cannot modify it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using PlayerAdded, CharacterAdded:Wait()

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	print("Adjusting.." .. plr.Name)
	plr.CharacterAdded:Wait()
	for _, child in pairs(plr.Character:GetDescendants()) do
		if child:IsA("Accessory") then
			print("accessory found")
			child.Handle.CanTouch = false
            child.Handle.CanQuery = false
		end
	end
end)

How can i make the script wait until the player succesfully loaded?

something like
repeat task.wait() until plr.Character:FindFirstChild("Accessory") ?


Player.CharacterAdded:Connect(function(char)

end)

I recently found older topic that cover this problem and all i had to do was wait for player appearence to load

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end
		
		for _, child in ipairs(character:GetChildren()) do
			local handle = child:FindFirstChild("Handle")
			if handle then
				handle.CanTouch = false
				handle.CanQuery = false
			end
		end
	end)
end)

Bare in mind that with your current implementation the touch/query setting would only be executed once (when the player first joins), you would need to wrap code inside of a “.CharacterAdded” event in order for it to be executed each time the player’s character is added (reloads/respawns etc.). Additionally, you don’t need to iterate over the character’s descendants, its children will suffice as accessories are always immediate children.

3 Likes