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

Attempt to index local 'msg' (a nil value)?

Asked by 5 years ago
Edited 5 years ago

This is the error I am getting. (https://gyazo.com/dc156d15e39ecb4eb8ea3e025d78f253)

So I am trying to make this FE compatible so it can't be hacked and reliable. This is my code.

LocalScript:

local RE = game:GetService("ReplicatedStorage")



RE.Jail.OnClientEvent:Connect(function(plr, msg)

if msg:sub(1,6) == "/jail " then

local TargetPlayer = game.Players:FindFirstChild(msg:sub(7))

if TargetPlayer then

local CJT = TargetPlayer:FindFirstChild("leaderstats"):FindFirstChild("Jail Time")

CJT.Value = 10

local JG = game:GetService("ReplicatedStorage"):FindFirstChild("JailGUI"):Clone()

JG.Parent = TargetPlayer:FindFirstChild("PlayerGui")

while wait(1) do

CJT.Value = CJT.Value - 1

JG.Holder.Time.Text = CJT.Value

if CJT.Value == 0 then

TargetPlayer:FindFirstChild("PlayerGui"):FindFirstChild("JailGUI"):Destroy()

CJT.Value = 0

TargetPlayer:LoadCharacter()

end

end

end

end

end)

ServerScript:

game.Players.PlayerAdded:Connect(function(plr)

local ls = Instance.new("IntValue",plr)

ls.Name = "leaderstats"

ls.Value = 0

local jt = Instance.new("IntValue",ls)

jt.Name = "Jail Time"

local defval = 0

jt.Value = defval

plr.Chatted:Connect(function(msg)

local RE = game:GetService("ReplicatedStorage")

RE.Jail:FireClient(plr,msg)

end)

end)

The local script is in StarterGui named JailSetter, the ServerScript is in ServerScriptService named Stats, and the Remote Event is in ReplicatedStorage named Jail. The JailGUI is in ReplicatedStorage. I have been coding for almost a year, then took a long break. Some help getting back into the swing of things would be very appreciated.

1
"msg" is being assigned to "plr". The first parameter passed by OnClientEvent is always the player yet the player should not appear in the tuple given to FireClient(). DeceptiveCaster 3761 — 5y
0
Now I am getting the error unable to cast value to to Object on line 12 of the Server Script? killerbrenden 1537 — 5y
0
please please please use the freaking Lua code button aandmprogameing 52 — 5y
0
killerbrenden the problem is I can not see the full script of the CJT value please write it aandmprogameing 52 — 5y
0
The CJT is an abbreviation for Change Jail Time which Jail Time is inside the players leaderstats thats on the leaderboard, it's a new variable that acts as the changing value for the value of jail time. killerbrenden 1537 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

As I said in the comment, you're improperly using the tuple given to FireClient(). The first thing in the tuple should not be the player, as that is already passed when OnClientEvent fires. Fix that line like this:

RE.Jail:FireClient(msg) -- msg should be the only thing being fired to OnClientEvent, because OnClientEvent doesn't automatically pass it like it passes the player who fired the RemoteEvent.
0
they probably already have launched the the event in a different script :| aandmprogameing 52 — 5y
0
My local script line goes like this: RE.Jail.OnClientEvent:Connect(function(msg) And my server script line goes like this: RE.Jail:FireClient(msg) I keep getting the error it's unable to cast value to Object on line 12 of server script. killerbrenden 1537 — 5y
0
That's a different error. Figure out what that one could be. DeceptiveCaster 3761 — 5y
0
I guess I'll do that. killerbrenden 1537 — 5y
0
Alright, I found it out. I had to change FireClient to FireAllClients, so it calls all the clients events and shows up on everybody's screen. Thank you for your help. killerbrenden 1537 — 5y
Ad

Answer this question