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

attempt to index local 'jun' (a nil value) Error?

Asked by 6 years ago

So i'm trying to a transformaton script (activated when used chat)

This is my script: function god() local Mouse = Player:GetMouse() local shirt = Player.Character:WaitForChild("Shirt") local pants = Player.Character:WaitForChild("Pants") shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=841007897" pants.PantsTemplate = "http://www.roblox.com/asset/?id=841019962" end

jun.Chatted:connect(function(Msg) local msg = Msg:lower() if string.sub(msg, 1, 7) == "destroyer" then wait(0.1) god() end if string.sub(msg, 1, 13) == "god" then wait(0.1) god() end if string.sub(msg, 1, 6) == "hakaishin" then wait(0.1) god() end if string.sub(msg, 1, 10) == "mortal" then wait(0.1) mortal() end if string.sub(msg, 1, 3) == "off" then wait(0.1) mortal() end end)

And i get this error: Players.ZuperZhadow.Backpack.LocalScript:9: attempt to index global 'jun' (a nil value)

Someone help? (Or if i'm wrong on this script then someone do one for me, it's just about changing clothes when you say the word "god" (without the " 's)

1 answer

Log in to vote
0
Answered by 6 years ago

It doesn’t seem like you are defining ‘jun’ in your code, the chatted event is for player instance, and since you haven’t defined jun, you really can’t connect a function to a non-existing event.

You can do

local jun = game.Players:FindFirstChild(“PlayerName”)

Or you can do

game.Players.PlayerAdded:Connect(function(jun)
— in this case, jun isn’t a specific player, but is the player declared when they join

jun.Chatted:Connect(function()
— code 
end)

end)
0
Thank you, that helped. But now when i say the word "god" it doesn't change my clothes. (same code just added yours in it) ZuperZhadow 0 — 6y
Ad

Answer this question