How to pass bool value from client to server by RemoteEvent?

Hello. I’m trying to make a hammer that has to be charged by .Activated before being able to be swung by .Deactivated . It also has to have a knockback effect after swinging.

Client:

local tool = script.Parent

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local rootPart = character:WaitForChild("HumanoidRootPart")

local remoteEvent = tool.RemoteEvent

local charge = script.Charge
local smash = script.Smash

local chargeTrack = animator:LoadAnimation(charge)
local smashTrack = animator:LoadAnimation(smash)

local cooldown = false
local charged = false
local hanging = false
local canKnockback = false

tool.Activated:Connect(function()
    if not cooldown and not hanging then
        cooldown = true

        if not charged then
            smashTrack:Stop()
            chargeTrack:Play()

            delay(chargeTrack.Length - 0.02999, function()
                chargeTrack:AdjustSpeed(0)
            end)

            charged = true
        end

        wait(1)
        cooldown = false
    end
end)

tool.Deactivated:Connect(function()
    chargeTrack:Stop()

    remoteEvent:FireServer(canKnockback)

    if charged then     
        smashTrack:Play()

        delay(smashTrack.Length - 0.02999, function()
            smashTrack:AdjustSpeed(0)

            rootPart.Anchored = true
            hanging = true
            canKnockback = true

            wait(1)
            smashTrack:Stop()

            rootPart.Anchored = false
            hanging = false
            canKnockback = false
        end)

        charged = false
    end
end)

Server:

local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

remoteEvent.OnServerEvent:Connect(function(player, command)
    print(player)
    if command then
        head.Touched:Connect(function(hit)
            local humanoid = hit.Parent:FindFirstChild("Humanoid")
            local character = humanoid.Parent
            local torso = character:WaitForChild("UpperTorso")

            if humanoid then
                torso.Transparency = 0.5 --just a test, not the actual knockback
            end
        end)
    end
end)

That’s what I’ve tried. But for some reason, nothing happens with the torso.

1 Like

You could make a BodyVelocity using instance.New and setting the Velocity on the BodyVelocity instance to the humanoidrootpart lookvector of the player who used the hammer and adding/deleting the bodyvelocity to game:GetService(“Debris”) after 1 second

1 Like