Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

FindFirstChild() + parameters isnt working inside a OnServerEvent ?

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

2 comments

0

Check the wiki on OnServerEvent. It passes the player object as its first argument followed by any sent in the remote event.

0

The player argument is the player, not the player's name. Try game.Players:FindFirstChild(player.Name)

2 answers

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)

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 !

This discussion is preserved as it was. New answers, comments, and votes are closed.