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

How do I get LocalPlayer in a normal script?

I am trying to check when a different player touches the LocalPlayer's right arm, but I need to do this in a normal script to actually deal damage. Any suggestions?

1 comment

1

playeradded, remote events, child added for workspace (check in players), etc

2 answers

✓ Accepted answer

You can't get the localplayer, there is none, however you could use a character added evnt and use the character object for that instead

1 comment

0

Oh, ok.

You can have a localscript that connects the right arm's touched event to a function that fires a remote event that your "normal script" will receive.

Local Script

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
local localPlayer = game.Players.LocalPlayer
local Character = localPlayer.Character or localPlayer.Character:Wait()

local function onTouched()
	RemoteEvent:FireServer()
end

Character:FindFirstChild("Right Arm").Touched:Connect(onTouched)

Server Script

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player)
	print("Right Arm touched")
end

1 comment

0

Generally, when possible you should't let localscripts handle things such as taking damaging, kicking players etc.

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