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

Why is the humanoid not damaging and I'm not damaging outside roblox studio?

Asked by 6 years ago

Here's the code, is there any problem with this code?


local plr = game.Players.LocalPlayer local CanDamagePlayers = true local damage = 32 script.Parent.Top.Touched:connect(function(p) if p.Parent:FindFirstChild("Humanoid") and CanDamagePlayers == true and p.Parent.Humanoid.Health > 0 then p.Parent.Humanoid:TakeDamage(damage) script.Parent.Sound:Play() plr.leaderstats.Pins.Value = plr.leaderstats.Pins.Value + 12 CanDamagePlayers = false wait(1) CanDamagePlayers = true end end)

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Assuming that is in a server script, you cannot get the LocalPlayer from the server in actual game servers. This is because LocalPlayer is used only to get the player who has ownership of a local script.

If this is a server script inside a tool, you should be able to convert it to a local script and it should work (as tools are individual to the owner and thus allows you to run local scripts within them)

However, if you have filtering enabled, the leaderstats will not be properly added and the damage would not be properly dealt if it was run from a local script (it would only occur for that client)

Because of this, something like this might work better in a server script:

local CanDamagePlayers = true
local Damage = 32

script.Parent.Top.Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") and CanDamagePlayers == true and    p.Parent.Humanoid.Health > 0 then
        p.Parent.Humanoid:TakeDamage(damage)
        script.Parent.Sound:Play()
    local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
        plr.leaderstats.Pins.Value = plr.leaderstats.Pins.Value + 12
        CanDamagePlayers = false
        wait(1)
        CanDamagePlayers = true
    end
end)

Bear in mind this is assuming the script is inside a tool, and that the tool has a part called Top inside.

0
Do you need a normal script? KetchupRBLX 0 — 6y
Ad

Answer this question