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

How to remove a tool when someone has it enabled?

Asked by
wjs3456 90
9 years ago

I have this short script here that I want to use to remove a certain tool. But the problem is if the player has it enabled it won't be removed. Is there a way to access what they have selected?

Here's the script:

first_infected.StarterGear.Shrike:remove()
    first_infected.Backpack.Shrike:remove()

Thanks!

0
I haven't tested it, but I edited my answer to include a different solution that may solve the problem? BlueTaslem 18071 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Tools, when equipped, are moved into the player's character.

Just check there, too (I'm unsure if deleting an equipped tool might have bad effects)

place = first_infected.StarterGear;
if place:FindFirstChild("Shrike") then
    place.Shrike:Destroy()
end
place = first_infected.Character;
if place:FindFirstChild("Shrike") then
    place.Shrike:Destroy()
end

This solution may fix the problem you saw:

place = first_infected.StarterGear;
if place:FindFirstChild("Shrike") then
    place.Shrike:Destroy()
end
place = first_infected.Character;
if place:FindFirstChild("Shrike") then
    local tool = place.Shrike;
    tool.Enabled = false;
    tool:Destroy()
end
0
Thanks it worked. Unfortuantely it keeps my arms in the same position. To fix it is it like Cframing? wjs3456 90 — 9y
1
Unfortunately I'm not sure how to fix it. I believe if they equip another tool and de-equip that, it will be fixed, but I'm not sure the most elegant way to fix this. BlueTaslem 18071 — 9y
0
Alright, thanks I'll play around with it. Appreciate the help :) wjs3456 90 — 9y
0
I'll try that but I I've started this below. wjs3456 90 — 9y
0
Mine worked. I'll edit mine to the full script wjs3456 90 — 9y
Ad
Log in to vote
1
Answered by
wjs3456 90
9 years ago
place = first_infected.Character;
        if place:FindFirstChild("Shrike") then
     place:FindFirstChild("Shrike").Parent = first_infected.Backpack
    wait()
    v.Backpack.Shrike:Destroy()
    end

It removes it to the backpack from where I can destroy it.

Answer this question