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

Why is this Tool Script not Working?

Asked by 9 years ago

This script is supposed to give you a tool when you sit in a seat, and remove it (and its GUI) when you unsit. However, when you unsit the first time, it won't work. It will give you a tool, but the tool will have no children, which is odd, since when I checked where the tool was stored, it was fine.

I have no idea what is going on. Can someone please help me? Here's the script:

local thing2 = game.ServerStorage.Minigun:clone()

function Seated(theSeated) 
local dude = game.Players:playerFromCharacter(theSeated.Part1.Parent)
if dude ~= nil then
thing2.Parent = dude.Backpack
end
end


function UNSeated(theSeated)
local dude = game.Players:playerFromCharacter(theSeated.Part1.Parent) 
if dude ~= nil then
if dude.Backpack:findFirstChild("Minigun") ~= nil then
    dude.Backpack.Minigun:remove()
elseif dude.Character:findFirstChild("Minigun") ~= nil then
    dude.Character.Minigun:remove()
end
if dude.PlayerGui:findFirstChild("GunDisplay") ~= nil then
    dude.PlayerGui.GunDisplay:remove()
end
end
end

script.Parent.ChildAdded:connect(Seated)
script.Parent.ChildRemoved:connect(UNSeated)

Answer this question