What do I want to achieve? I want to make a button that removes a model inside the player.
What is the issue? When I scripted it, the script does nothing.
What solutions have you tried so far? I have tried to find anything on the Devforum and YouTube. Sadly nothing.
function onTouched(hit)
local d = hit.Parent:GetChildren()
for i=1, #d do
if (d[i].className == "Bandages") then
d[i]:remove()
end
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
local d = hit.Parent:GetChildren()
for i, v in pairs(d) do
if v:FindFirstChild('Bandages') then
v:FindFirstChild('Bandages'):Destroy()
end
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
local d = hit.Parent:GetChildren()
for i, v in pairs(d) do
if v.ClassName == "Bandages"
v:Destroy()
end
end
end
script.Parent.Touched:connect(onTouched)
Since I don’t really know how your models are structured here’s my idea:
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)
Depending on what are bandages (and where they are located) this should work for most cases