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

Why is "w" in a client event a nil value?

Asked by 6 years ago
Edited by M39a9am3R 6 years ago

so I made this script that when you touch a part it fires a client event to another script

script that fires the event:

v.ss.Touched:Connect(function(plr)

        local w = v:WaitForChild("ww")
            game.workspace.CurrentCamera.CFrame = camra2.CFrame
            game.workspace.CurrentCamera.CameraType = "Scriptable"
            s1:FireClient(plr,w)
end)

local script that makes the function when the event is fired:

s1.OnClientEvent:connect(function(plr,w)
                print(":>")



            game.Players.LocalPlayer.Character.Humanoid:MoveTo(w.Position)
end)

why does it say that w is a nil value?

btw there are local things that I haven't added since it's not necessary and has nothing to do with the initial question.

0
Edited for code block. M39a9am3R 3210 — 6y
0
On line one of the local script, remove the plr argument from the function. RayCurse 1518 — 6y
0
thank you so much :D Unbunn_makes 48 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Firstly on a side note, you can't access the CurrentCamera from a server script, only from a local script, so you will have to move that.

As for why w is a nil value, when you use FireClient from the server, you must enter the player argument as you have done to identify which player's client you want to fire the event on. However, on receiving the event in the local script, the player is not given as an argument, as you do not need it to identify the player. Because of this, the "w" variable is actually the variable you define as plr in the local script, and the variable defined as w is nil. So to fix this, remove the plr variable as an argument in the local script and only have w instead.

sl.OnClientEvent:Connect(function(w)

instead of

sl.OnClientEvent:Connect(function(plr,w)
Ad

Answer this question