Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

Tool Removal Question -- Please Help

  • This website was created by Roblox members to replace the official forums (because Roblox shut them down) Join us if you like Roblox!

drco12

New Member
Reputation: 0 / 0 / 0
Nov 24, 2021
5
0
1
Roblox
drco12
Below is the script for a game I am building. I know it works up to line 13, but after that I am not sure how to make the script remove tools from players when they get "infected."


local players = nil

local character = nil

local infection = nil

local numInfected = 0



while true do

wait(1)

numInfected = 0

players = game.Players:children()

for i=1,#players do

character = players.Character

if character ~= nil then

if character:findFirstChild("Infected")~= nil then ---- Line 13

for i,item in pairs(script.Parent:GetChildren()) do

if item.Name == "Pistol" and item:IsA("Tool") then

item:Destroy()

end

end

for i,item in pairs(game.Players[script.Parent.Name].Backpack:GetChildren()) do

if item.Name == "Pistol" and item:IsA("Tool") then

item:Destroy()

end

end

end

end

end

end
 

drco12

New Member
Reputation: 0 / 0 / 0
Nov 24, 2021
5
0
1
Roblox
drco12
This is what I came up with, but it still does not work. Any help ya'll could offer would be amazing!


Remove Tools Code:
local Tools = {"Pistol", "AK47", "M1 garand", "M16"}





local Players = game:GetService("Players")

local Character = Players.LocalPlayer.CharacterAdded:wait()

local db = false





for i, v in ipairs(Tools) do

    local Hum = Character:findFirstChild("Humanoid")

    if Hum == nil then wait(0.1) db = false return end



    if Hum:findFirstChild("Infected").Value then

        local tool = Character:WaitForChild("Backpack"):GetChildren(v)

        if tool then tool.Enabled = false end

    end

end
 

ElHomburgerGuy

If you won't let yourself fail, you won't improve
Reputation: 5 / 0 / 1
Apr 24, 2019
6,713
24
2,631
113
Anonymous in the USA
Roblox
PieroWasTaking
LocalPlayer only works for a LocalScript so if this is a ServerScript then it won't work. Would be better to use GetPlayerFromCharacter instead.

ExampleCode:
local Players = game:GetService("Players")

local Character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)