I am having trouble connecting a RemoteEvent firing in one script to a RemoteEvent firing in another script. This is a sort of follow-up to my last post.
This part of the code is meant to fire the event on the given parameter:
local HairColorButtonArray = workspace.SettlerLobby.ScriptedObjects.MasterCCDisplay.MainDisplay.GuiMasterParent.HairSelectionMainframe.HairColors:GetChildren()
local ClickSound = workspace.SettlerLobby.ScriptedObjects.MasterCCDisplay.MainDisplay.Click
local SettlerLobbyEvents = game.ReplicatedStorage.LobbyEvents.SettlerLobbyEvents
for i , v in pairs(HairColorButtonArray) do
if v:IsA("ImageButton") then
v.MouseButton1Click:Connect(function()
ClickSound:Play()
if v.Name == "01HairColor" then
SettlerLobbyEvents.HairColorEvent:FireServer("01HairColor")
end
if v.Name == "02HairColor" then
SettlerLobbyEvents.HairColorEvent:FireServer("02HairColor")
end
end)
end
end
This part of the code is the reciever, meant to detect the parameters and take action given the parameter:
local HCServerEvent = game.ReplicatedStorage.LobbyEvents.SettlerLobbyEvents.HairColorEvent
local Char = game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
HCServerEvent.OnServerEvent:Connect(function(player, event)
if event == "01HairColor" then
print("Debug 01HairColor")
end
if event == "02HairColor" then
print("Debug 02HairColor")
end
end)
I’m getting no error messages via the devlog. Please help!
The LocalPlayer property is not replicated to the server (scripts) and can only be used on the client (local scripts). Right now, the server script will throw an error and stop executing when attempting to index the Character property of the LocalPlayer as it will always be nonexistent on the server.
Try removing all references to the LocalPlayer property on the server as such:
local HCServerEvent = game.ReplicatedStorage.LobbyEvents.SettlerLobbyEvents.HairColorEvent
HCServerEvent.OnServerEvent:Connect(function(player, event)
if event == "01HairColor" then
print("Debug 01HairColor")
end
if event == "02HairColor" then
print("Debug 01HairColor")
end
end)
Tried it, still no dice. The problem is most likely with the receiver, not the event firing part (as you probably know), and the 2nd bit of the script is in ServerScriptService
You don’t need to detect the player as a RemoteEvent does that anyway.
local HCServerEvent =
game.ReplicatedStorage.LobbyEvents.SettlerLobbyEvents.HairColorEvent
HCServerEvent.OnServerEvent:Connect(function(player, event)
local Char = player.Character
if event == "01HairColor" then
print("Debug 01HairColor")
end
if event == "02HairColor" then
print("Debug 02HairColor")
end
end)