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

I want to replace game.Players.LocalPlayer.Character but it won't work?

I was about to replace it cause it just don't work in-game. But it won't work. Any help?

local playerfinding = game.Players.LocalPlayer
local player = playerfinding:FindFirstChild(game.Players.LocalPlayer.Name)

This is the error I receive and game.Players.LocalPlayer.Character won't work in-game actually, it sends an error on Developer Console.

How to fix this? I wanted to shoot my fire script both in-game and in-studio. Error I recieve: 18:04:12.336 - Players.cherrythetree.Backpack.LocalScript:7: attempt to index local 'player' (a nil value)

1 comment

0

@cherrythetree detect the Character and then the Name. I'll give an example.

2 answers

The character is located in the workspace, not players. At least one of the below scripts should work, I'm not sure which.

local playerfinding = game.Players.LocalPlayer
local player = game.Workspace[playerfinding]
local playerfinding = game.Players.LocalPlayer
local player = game.Workspace[playerfinding.Name]

1 comment

0

Thanks for the answer but still not working since cherrythetree was not a parent of Workspace.

local playerfinding = game.Players.LocalPlayer
local char = playerfinding.Character
local name = playerfinding.Name
if playerfinding ~= nil then
	if char ~= nil then
		local m = game.Workspace:FindFirstChildWhichIsA("Model")
		if m.Name == playerfinding.Name then
			-- Code here
		end
		if not char.Parent == game.Workspace then return end
	end
end
		

This should work. It detects if the character is in the workspace.

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