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

Roblox Fire Extinguisher with Remote Events not working?

Asked by 5 years ago

The scripts aren't showing any signs of working, the only is error is: " 11:28:20.502 - Players.Gameplay28.Backpack.FireExtinguisher.FireEvent.Script:21: attempt to index a nil value" which I'm guessing is because the Fire Extinguisher goes into the character when equiped. So how do I fix this, is there a way I can get the character from the player?

Server Script:

local debounce = false
local timedebounce = 0.1
local spraying = false
local torso = nil
local offset = 5
local debris = game:GetService("Debris")

game.ReplicatedStorage.BubbleEvent1.OnServerEvent:Connect(function(player)
    print(player.Backpack:FindFirstChild("FireExtinguisher"))
torso = player.Backpack:FindFirstChild("FireExtinguisher").Parent:FindFirstChild("Torso", false) or player.Backpack:FindFirstChild("FireExtinguisher").Parent:FindFirstChild("UpperTorso", false)
end)

game.ReplicatedStorage.BubbleEvent2.OnServerEvent:Connect(function(player)
spraying = false
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=27787143"
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.FoamSound:Stop()
    end)

game.ReplicatedStorage.BubbleEvent3.OnServerEvent:Connect(function(player)
    spraying = true
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=27787226"
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.FoamSound:Play()
    sprayBubbles()
end)

game.ReplicatedStorage.BubbleEvent4.OnServerEvent:Connect(function()
    spraying = false
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=27787143"
    player.Backpack:FindFirstChild("FireExtinguisher").Handle.FoamSound:Stop()
end)

game.ReplicatedStorage.BubbleEvent5.OnServerEvent:Connect(function()
    while spraying do

        local sprayDir = torso.CFrame.lookVector.unit

        local bubbleClone = bubble:clone()
        local torsoNormal = torso.CFrame.lookVector
        local denom = math.abs(torsoNormal.x) + math.abs(torsoNormal.z)
        local posX = 5 * (torsoNormal.x/denom)
        local posZ = 5 * (torsoNormal.z/denom)
        bubbleClone.Position = Vector3.new(player.Backpack:FindFirstChild("FireExtinguisher").Handle.Position.x + posX,player.Backpack:FindFirstChild("FireExtinguisher").Handle.Position.y,player.Backpack:FindFirstChild("FireExtinguisher").Handle.Position.z + posZ)
        bubbleClone.Velocity = Vector3.new(sprayDir.x,sprayDir.y + 0.5, sprayDir.z) * 50
        bubbleClone.Size = Vector3.new(math.random(1,2),math.random(1,2),math.random(1,2))
        bubbleClone.Parent = game.Workspace
        game.ReplicatedStorage.BubbleEvent5:FireServer()
    end
        bubbleClone.Touched:Connect(function(h)
            for i,v in pairs(h:GetChildren()) do
                if v:IsA("ParticleEmitter") then
                    script.Parent.FireEvent:FireServer(v)
                end
                end
            wait(0.05)
debris:AddItem(bubbleClone, 2)
    end)
    end)
script.Parent.OnServerEvent:Connect(function(p,fire)
    if p.Name == script.Parent.Parent.Parent.Name then
    if fire.Enabled == false or debounce == true then
        return
    end
    print(fire.Parent)
    if fire.Rate <= 0 then
        fire.Enabled = false
    end
    fire.Rate = fire.Rate - 2
    debounce = true
    wait(timedebounce)
    debounce = false
    end
end)

Local Script:

local Tool = script.Parent
local spraying = false
local torso = nil
local offset = 5
local debris = game:GetService("Debris")

local bubble = Instance.new("Part")
bubble.Shape = 0
bubble.formFactor = 0
bubble.Size = Vector3.new(1,1,1)
bubble.Transparency = 0.2
bubble.BottomSurface = "Smooth"
bubble.TopSurface = "Smooth"
bubble.CanCollide = true

function onEquipped(mouse)
    mouse.Button1Down:connect(onButton1Down)
    mouse.Button1Up:connect(onButton1Up)
    game.ReplicatedStorage.BubbleEvent1:FireServer()
end

function onUnequipped()
    game.ReplicatedStorage.BubbleEvent2:FireServer()

end

function onButton1Down(mouse)
game.ReplicatedStorage.BubbleEvent3:FireServer()
end

function onButton1Up(mouse)
    game.ReplicatedStorage.BubbleEvent4:FireServer()
end

function sprayBubbles()
        wait()
game.ReplicatedStorage.BubbleEvent5:FireServer()
        end
Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)

0
player.Character lol TiredMelon 405 — 5y
0
Right, I'm dumb. Gameplay28 139 — 5y

Answer this question