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

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

Asked by 6 years ago
Edited 6 years ago
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?

0
Is this a local script or a script? Prestory 1395 — 6y
0
regular script SirTottenhamcake 22 — 6y
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. supermariodeadtolive 55 — 6y
0
i changed it to a localscript and still doesnt work but this time doesnt even tell me why it doesnt work SirTottenhamcake 22 — 6y
View all comments (9 more)
0
You realise this code is not meant to do anything this is all just variables Prestory 1395 — 6y
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 SirTottenhamcake 22 — 6y
0
So can we have the full script? maybe that will help?? Prestory 1395 — 6y
0
there u go SirTottenhamcake 22 — 6y
0
Torso, not Chest supermariodeadtolive 55 — 6y
0
chest is the name of another thing welded to the character & is inside the character model SirTottenhamcake 22 — 6y
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) supermariodeadtolive 55 — 6y
0
try debugging it. i am new to Lua, this thing is out of my reach. supermariodeadtolive 55 — 6y
0
script is meant to work by touching a part which clones a gui into the frame SirTottenhamcake 22 — 6y

1 answer

Log in to vote
1
Answered by
arshad145 392 Moderation Voter
6 years ago

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.connectis 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.

Ad

Answer this question