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

Light saber blade won't turn on/off when inputting Q?

Asked by 3 years ago

I'm building a light saber tool and using some guy's tutorial from about a year ago, and currently I'm trying to make the blade on/off system. When I go in game and press "Q" to turn it on nothing happens, I don't even get an error message. It uses 2 scripts, a local and a normal script:

Normal Script

local tool = script.Parent

local damage = 20

local inner = tool.Emitter.Inner
local outer = tool.Emitter.Outer

tool:WaitForChild("Blade").Touched:Connect(function (hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid:TakeDamage(damage)
    end
end)

tool:WaitForChild("RemoteEvent").OnServerEvent:Connect(function (player, state)
    if state then
        tool.Emitter.Inner.Enabled = true
        tool.Emitter.Outer.Enbaled = true
    else
        tool.Emitter.Inner.Enabled = false
        tool.Emitter.Outer.Enbaled = false
    end
end

Local Script:

local uis = game:GetService("UserInputService")

local tool = script.Parent
local attack = tool:WaitForChild("Attack")

local player = game.Players.LocalPlayer

local equipped = false

local on = false

tool.Activated:Connect(function ()
    local animation = player.Character.Humanoid:LoadAnimation(attack)
    animation:Play()
end)


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

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

local function turnOff()
    on = false
    tool.RemoteEvent:FireServer(false)
end

local function turnOn()
    on = true
    tool.RemoteEvent:FireServer(true)
end

uis.InputBegan:Connect(function (input, processed)
    if processed then return end

    if input.KeyCode == Enum.KeyCode.Q and equipped then
        if on then 
            turnOff()
        else 
            turnOn()
        end
    end
end)

Any other stuff is for the attack animation and damage dealing script.

Can anyone help?

Answer this question