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

Replacement for LocalPlayer? / Hit Box system might be garbage

Asked by
Bruvis 1
2 years ago
Edited 2 years ago

Long post and I'm still new to scripting. So,

I was following a tutorial (Link)(Might be an outdated method) I decided to follow this tutorial to make a damage system. He puts the Remote Function in the Local script as a child he uses and he adds a normal script as a child of the Remote Function.

Followed it . It didn't do any damage, so I thought to change the script to use a Remote Function in the Replicated Storage.

Local Script works fine and no error, but the script I used to activate the Remote function can no long use LocalPlayer. Is there a replacement for this Also please let me know if I need to change the way I need to do this.

local rs = game:GetService("ReplicatedStorage")
local punching = rs:WaitForChild("ThePunch")

Enabled = true

punching.OnServerEvent:Connect(function(Action, Player, numb1)
    local player = game.Players.LocalPlayer
    local char = player.Character

    if Enabled == false then
        return
    end
    if Action == "Combat" then
        for i, v in pairs(workspace:children()) do
            if v:FindFirstChild("Humanoid") and v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Debounce") and v ~= char then
                if (v.HumanoidRootPart.Position-char.HumanoidRootPart.Position).magnitue <= 5 then
                    v.Humanoid:TakeDamage(5)
                end
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by
HEMAN_9 70
2 years ago

When writing code on the server, the script will not automatically know what "LocalPlayer" means, Since your connected function already has a variable called "Player" I would advise using that to get to the player instead of the variable you made on line 7. Hope this helps

1
Hey thanks for the reply but is there a way you can show me what you mean? Bruvis 1 — 2y
0
Sorry for the late response, on line 7 you write " local player = game.Players.LocalPlayer" which a server script cant recognize. Instead, anywhere where you would have used that variable on line 7, you instead use the parameter called "Player" which is the second parameter of the function on line 6. Basically, remove line 7 and change line 8 to "local char = Player.Character" capital P HEMAN_9 70 — 2y
Ad

Answer this question