#lightsaber sound not working

1 messages · Page 1 of 1 (latest)

soft moth
#

i want that the brrrr sound for my lightsaber only comes when i turn it on and the script for that is not realy working can someone help

#

local tool = script.Parent
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")

local equipped = false
local isOn = false -- merkt sich ob das Schwert "aktiv" ist

tool.Equipped:Connect(function()
equipped = true
end)

tool.Unequipped:Connect(function()
equipped = false
end)

uis.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E and equipped then
local handle = tool:FindFirstChild("Handle")
if not handle then return end

    if isOn then
        local deactivateSound = handle:FindFirstChild("DeactivateSound")
        if deactivateSound then
            deactivateSound:Play()
        end
        isOn = false
    else
        local activateSound = handle:FindFirstChild("ActivateSound")
        if activateSound then
            activateSound:Play()
        end
        isOn = true
    end
end

end)

#

thats the script for the sound ID when it turns off and on

#

local tool = script.Parent
local player = nil
local equipped = false
local laserActive = false

local soundOn = tool:WaitForChild("Sound_On")
local soundOff = tool:WaitForChild("Sound_Off")
local soundLoop = tool:WaitForChild("Sound_Loop")

tool.Equipped:Connect(function()
equipped = true
player = game.Players:GetPlayerFromCharacter(tool.Parent)
end)

tool.Unequipped:Connect(function()
equipped = false
if laserActive then
soundOff:Play()
soundLoop:Stop()
laserActive = false
end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if not equipped or not player then return end
if gameProcessed then return end

if input.KeyCode == Enum.KeyCode.E then
    if not laserActive then
        soundOn:Play()
        soundLoop:Play()
        laserActive = true
    else
        soundOff:Play()
        soundLoop:Stop()
        laserActive = false
    end
end

end)