Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

Deleting a part with Mouse.Target?

Asked by 9 years ago

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
0
Ok... Really... Why keep downvoting... TypicalModerator 110 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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
0
"Target" is a read only value. It can't be destroyed. TypicalModerator 110 — 9y
0
Yes it can. Read-Only means you can't set the value manually, but you can still modify what is given. DigitalVeer 1473 — 9y
0
Ok then... I tried it like a year ago and it didn't work and said it's read only.. TypicalModerator 110 — 9y
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 DigitalVeer 1473 — 9y
Ad
Log in to vote
0
Answered by
Tynezz 0
9 years ago

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().

Answer this question