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

Why is my remote event passing along bad data?

Asked by
stardon 12
7 years ago

I'm trying to have a local script fire a remote event to the server that allows a player to join a team of their choosing. The exact error message I receive is

16:45:25.304 - Workspace.Event Handler:10: attempt to index local 'playa' (a nil value)

Through printing what playerName and teamName are in the server script I've determined that both varibles are the string "stardon" Why? One should be a team and not a text string.

Here are my scripts

Local GUI script

01function click()
02    --Arguments to pass toward the server script
03    local PN = script.Parent.Parent.Parent.Parent.Parent.Parent.Name
04    local targetTN = game.Teams[script.Parent.Text]
05 
06    --Pass em' to the server
07    local ReplicatedStorage = game:GetService("ReplicatedStorage")
08    local GiveMeJob = ReplicatedStorage:WaitForChild("GiveMeJob")
09 
10    GiveMeJob:FireServer(PN, targetTN)
11end
12script.Parent.MouseButton1Click:connect(click)

Server Event Handling Script

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local GiveMeJob = ReplicatedStorage:WaitForChild("GiveMeJob")
03local spawns = game.Workspace.SpawnLocations:GetChildren()
04 
05local function hereIsJob(playerName, teamName)
06    wait(0.1)
07    print(teamName)
08    local targetTeamColor = teamName.TeamColor
09    local playa = game.Players:FindFirstChild(playerName)
10    playa.Team = teamName
11 
12    for i=1, #spawns do
13        if spawns[i].teamName == targetTeamColor then
14            playa.Character:MoveTo(spawns[i].Position + Vector3.new(0,10,0))
15        end
16    end
17end
18GiveMeJob.OnServerEvent:Connect(hereIsJob)
0
Try 'local PN = game.Players.LocalPlayer.Name' thesit123 509 — 7y
0
I'm having the same problem. It still thinks both values I pass along are "stardon" stardon 12 — 7y
0
The first argument of a remote event sent from client-server is already the player's name automatically, your first two arguments both send the player name and the third argument isn't received by the server Vulkarin 581 — 7y
0
Oh! Thanks a bunch! stardon 12 — 7y

Answer this question