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

FindFirstChild() + parameters isnt working inside a OnServerEvent ?

Asked by 6 years ago
Edited 6 years ago

Im trying to make a store script using FE , I got everything working but the cloning of the product bought , the problem is the script for the Remote Event triggering isnt working with FindFirstChild() with parameters

Eg :- (RemoteEvent inside of ReplicatedStorage / Script for RemoteEvent inside of ServerScriptStorage)

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player)
    print(game.Players:FindFirstChild(player))

end)

Output is :-nil yet this code works in other Events

but if I refer to the player directly e.g my username then it works :-

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player)
    print(game.Players:FindFirstChild("ElementalEnder9"))

end)

I apologise for my bad explaining skills

0
Check the wiki on OnServerEvent. It passes the player object as its first argument followed by any sent in the remote event. User#5423 17 — 6y
0
The player argument is the player, not the player's name. Try game.Players:FindFirstChild(player.Name) UgOsMiLy 1074 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

The passed "player" argument is the player itself, so no need to find it in players again , just do this :

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player)
    print(player)

end)

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This was an example script , the real script involves stringValues being passed through the client to server , if I try to find a child by the Values name , I get nil as the output but if I just print the child I get the correct output and if try to print the item Im trying to find I still get nil

E.g :-

local Event = game:GetService("ReplicatedStorage").Stores.JacksFishing.Dropper

Event.OnServerEvent:Connect(function(player ,I1N)   -- I1N is Value for Item Name
print(game.ReplicatedStorage.Stores.JacksFishing.Items:FindFirstChild(I1N)) -- Output as nil
local Item1 = game.ReplicatedStorage.Stores.JacksFishing.Items:FindFirstChild(I1N):Clone() -- Output as `attempt to index a nil value`
Item1.Parent = game.Workspace

print(I1N) -- Output as Item Name

end)

I hope I've explained better this time and thanks for responding really soon !

Answer this question