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

Not sure why my remote event isn't working?

I want a remoteEvent to pass the player who has just been joined through to the server side (playerAdded will be changed later I'm just using it as an example) and it will send the player through who has just joined and it will print their name off in the script (This will also be changed). However, I'm not sure if I've set up the scripts wrong.

Local script:

local remoteEventPlayer = game.ReplicatedStorage.robloxLocalPhoto

game.Players.PlayerAdded:Connect(function(player)
	remoteEventPlayer:FireServer(player)
end)

remoteEventPlayer:FireServer(player)

Server script:

local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto

local function playerPhoto(player)
	local playerName = player.Name
	print(playerName)
end

remoteEventLocalPhoto.OnServerEvent(playerPhoto)

Whenever I test, it just says this:

' 15:38:07.221 - ServerScriptService.userPhoto:3: attempt to call field 'OnServerEvent' (a userdata value)'

Why?

1 answer

I figured out what the problem was, it was because I wasn't using :Connect on the server script after the 'OnServerEvent'. The new updated code (With some changes) looks something like this:

Code:

Local script:

local robloxLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto

script.Parent.MouseButton1Click:Connect(function(player)
	robloxLocalPhoto:FireServer(player)
end)

Server script:

local remoteEventLocalPhoto = game.ReplicatedStorage.robloxLocalPhoto

local function playerPhoto(player)
	print(player.Name)
end

remoteEventLocalPhoto.OnServerEvent:Connect(playerPhoto)

Another thing that I forgot to do was index the player, this was just causing the event but wasn't sending anything over, so I had to change the parameters of the functions.

I hope this helps those in the future who have had the same problem, that is why I answered it.

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