Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Deleting a part with Mouse.Target?

I'm making a game, and in the game you have to collect food and things, how do I remove a part when collected since Mouse.Target is Read Only? And I tried using GetFullName().

elseif Target:findFirstChild("Food") then
				if not FoodDebounce then
					FoodDebounce = true
					if Food.Value < Food.Max.Value then
						Food.Value = Food.Value + 5
					end
					if Food.Value > Food.Max.Value then
						Food.Value = Food.Max.Value
					end
					local Part = Target:GetFullName()
					Part:Remove()
					wait(2)
					FoodDebounce = false
				end

1 comment

0

Ok... Really... Why keep downvoting...

2 answers

✓ Accepted answer

#GetFullName

GetFullName is a method that returns a string that contains the path to that instance. For example, if there was a part in workspace, using GetFullName on that part would return 'game.Workspace.Part'

So you are trying to remove the part name instead of the actual part.

To fix this, you just have to instead do:

target:Destroy()
wait(2)
FoodDebounce = false

4 comments

0

"Target" is a read only value. It can't be destroyed.

0

Yes it can. Read-Only means you can't set the value manually, but you can still modify what is given.

0

Ok then... I tried it like a year ago and it didn't work and said it's read only..

0

It is read only. Do you know what that means? It means that you can do, 'local part = mouse.Target' but you can't do, 'mouse.Target = workspace.Baseplate'. You can still modify what you are given from the read-only value

Is it read only?

elseif Target:findFirstChild("Food") then
                if not FoodDebounce then
                    FoodDebounce = true
                    if Food.Value < Food.Max.Value then
                        Food.Value = Food.Value + 5
                    end
                    if Food.Value > Food.Max.Value then
                        Food.Value = Food.Max.Value
                    end
                    local Part = Target
                    Part:Destroy()
                    wait(2)
                    FoodDebounce = false
                end

I'm pretty sure it's not read only. Anyways, I changed :Remove() to :Destroy().

This discussion is preserved as it was. New answers, comments, and votes are closed.