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

I'm trying to use Instance.new('ForceField') but my player still TakeDamage(30), how to stop?

Asked by 3 years ago
Edited 3 years ago

The forcefield doesn't stop damage taken even when ``force.Visible = true

local function spawnShield()
    local playerCFrame = nil
    shield = replicatedStorage:WaitForChild('Shield'):Clone()
    shield.Parent = game.Workspace
    force = Instance.new('ForceField')
    force.Visible = false

    force.Parent = player.Character.Humanoid.Parent
    runService:BindToRenderStep('shield',1,function() -- fake shield that follows the player
        playerCFrame = player.Character.HumanoidRootPart.CFrame
        shield.CFrame = playerCFrame * CFrame.Angles(0,0,math.rad(90))
    end)
end

local function destroyShield()
    runService:UnbindFromRenderStep('shield')
    shield:Destroy()
    force:Destroy()
end


uis.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        debounce,hitBool = false,false
        playslash = player.Character.Humanoid:LoadAnimation(blockAnim)
        playslash:Play()
        spawnShield()
    end
end)

uis.InputEnded:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        debounce = true
        intValue.Value = 0
        playslash:Stop()
        if shield ~= nil then
            destroyShield()
        end
    end
end)

1 answer

Log in to vote
0
Answered by
rabbi99 714 Moderation Voter
3 years ago
Edited 3 years ago

If the client creates the ForceField and the server does damage., the client still gets damaged, because the server doesn't know the player has a ForceField. In order to fix this, you need to run the spawnShield function on the ServerSide.

Ad

Answer this question