Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Replacement for LocalPlayer? / Hit Box system might be garbage

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

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

2 comments

1

Hey thanks for the reply but is there a way you can show me what you mean?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.