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

"attempt to index local 'LocalP' (a nil value)" how do i fix this?

local sp = script.Parent
local db = true
local LocalP = game.Players.LocalPlayer
local Player = LocalP.Character
local Azarth = script.Parent.Option.Frame.ImageButtonFinalFlash
local Azarth2 = script.Parent.Option.Frame.ImageButtonFinalFlash2
local Azarth3 = script.Parent.Option.Frame.ImageButtonFinalFlash3
local Azarth4 = script.Parent.Option.Frame.ImageButtonFinalFlash4
local Bot = script.Parent.Parent.Parent.Suit
local Flash = Bot.Arm1.Middle:WaitForChild("FinalArmCharge")
local Flash2 = Bot.Chest.Middle:WaitForChild("FinalCharge")

sp.Touched:connect(function(hit)
	if hit and hit.Parent:findFirstChild("Humanoid") and db then 
		db = false
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.PlayerGui:findFirstChild("Option") then 
			Azarth:Clone().Parent = player.PlayerGui:WaitForChild("Option"):WaitForChild("Frame")
			Azarth2:Clone().Parent = player.PlayerGui:WaitForChild("Option"):WaitForChild("Frame")
			Azarth3:Clone().Parent = player.PlayerGui:WaitForChild("Option"):WaitForChild("Frame")
			Azarth4:Clone().Parent = player.PlayerGui:WaitForChild("Option"):WaitForChild("Frame")
		Flash:Clone().Parent = Player.Arm1.Middle
		Flash:Clone().Parent = Player.Arm2.Middle
		Flash2:Clone().Parent = Player.Chest.Middle
		end
		wait()
		db = true
	end
end)

this is the whole script but then it tells me "attempt to index local 'LocalP' (a nil value)". any way to counter this?

13 comments

0

Is this a local script or a script?

0

regular script

0

it's a script, localplayer is not in scripts because it runs on the server so it doesn't know which player is you, but localscript is on the client.

0

i changed it to a localscript and still doesnt work but this time doesnt even tell me why it doesnt work

0

You realise this code is not meant to do anything this is all just variables

0

this is the first part of the script i didnt put the full thing in as it was the variables that i had a problem with

0

So can we have the full script? maybe that will help??

0

there u go

0

Torso, not Chest

0

chest is the name of another thing welded to the character & is inside the character model

0

change "LocalPlayer" to "SirTottenhamcake"  OR put the script in "StarterPlayer" > "StarterPlayerScripts" and change "game.Players.LocalPlayer" into "script.Parent.Parent.Parent.Parent" (works or not works based on your Parenting System)

0

try debugging it. i am new to Lua, this thing is out of my reach.

0

script is meant to work by touching a part which clones a gui into the frame

1 answer

Hello,

You seem new to Rbx.Lua.

Things you can learn :

1.LocalPlayer can only be used in a LocalScript.

2.You can use PlayerAdded event to get the joining players.

3.***connect***is deprecated , it is better to use Connect

--//This Script must be inside of a part//-- 

local db = true
local part = script.Parent
local gui = game.ReplicatedStorage:FindFirstChild('Gui')--<< Place the gui you want on that path... script.Parent.Option.Frame.ImageButtonFinalFlash
local Azarth = gui.Opition.Frame.ImageButtonFinalFlash
local Azarth2 = gui.Option.Frame.ImageButtonFinalFlash2
local Azarth3 = gui.Option.Frame.ImageButtonFinalFlash3
local Azarth4 = gui.Option.Frame.ImageButtonFinalFlash4
local Bot = gui.Parent.Parent.Suit
local Flash = Bot.Arm1.Middle:WaitForChild("FinalArmCharge")
local Flash2 = Bot.Chest.Middle:WaitForChild("FinalCharge")

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") and db then -- You cannot hit 'nil'
		db = false
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.PlayerGui:FindFirstChild("Option") then
			local g1 = gui:Clone()
			g1.Parent = player.PlayerGui
			Azarth:Clone().Parent = g1.Option.Frame
			Azarth2:Clone().Parent =  g1.Option.Frame
		    Azarth3:Clone().Parent =  g1.Option.Frame
            Azarth4:Clone().Parent =  g1.Option.Frame
        	--[[Flash:Clone().Parent = 
        	Flash:Clone().Parent = player.Arm2.Middle
        	Flash2:Clone().Parent = player.Chest.Middle
			]]--			
		end
	end
	wait()
	db = true
end)

That's all for the script. You need to adjust certain paths and such.

Thank you for reading!

Please upvote this post and accept it as an answer if it helped you.

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