Getting an error while trying to fire to the client

So I made a table to fire to the client, and it’s giving me an error that “Outcome is not a valid member of player”. Why is the script getting confused with my table and the player? I put the arguements right I’m pretty sure…

Error:
image

Server Script:

DialogueRemote.OnServerEvent:Connect(function(player, Data)
	
	--Clothing
	local ClothesFolder = game.Workspace.Shop.Clothes
	local ClotheModel1ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel1").Shirt.ShirtTemplate
	local ClotheModel2ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel2").Shirt.ShirtTemplate
	local ClotheModel3ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel3").Shirt.ShirtTemplate

	local ClotheModel1PantsTemplate = ClothesFolder:WaitForChild("ClotheModel1").Pants.PantsTemplate
	local ClotheModel2PantsTemplate = ClothesFolder:WaitForChild("ClotheModel2").Pants.PantsTemplate
	local ClotheModel3PantsTemplate = ClothesFolder:WaitForChild("ClotheModel3").Pants.PantsTemplate
	local Player = game:GetService("Players")
	local Char = player.Character
	local Stat = MainModule.GetStats(Char)
	local Yen = Stat.Yen
	
	if Data.Outcome == "Checking" then
		if Yen.Value < 50 then 
			local Data = { Outcome = "Invalid"}
			DialogueRemote:FireClient(player, Data)
			
		elseif Yen.Value >= 50 then
			local Data = { Outcome = "Valid"}
			DialogueRemote:FireClient(player, Data)
			
 		end
	end
	end)

local script:

	LeftClickToBuy.MouseButton1Click:Connect(function()
			--Need to make some CharacterAdded function
				
				
				local data = {Outcome = "Checking"}
				Dialogueremote:FireServer(player, data)
			
			Dialogueremote.OnClientEvent:Connect(function(player, Data)
				
				if Data.Outcome == "Invalid" then 
					BuyGuiFrame:WaitForChild("Cost").Text = "Invalid Funds"
					
				elseif Data.Outcome == "Valid" then
					BuyGuiFrame:WaitForChild("Cost").Text = "Successfully Purchased!"
				end
				
			end)
				

The player isn’t passed to :FireServer. The first argument should be the data table.

Are you sure how would that make sense when everything else is the player first and then the data table??

I misread your question actually, but the premise still applies. The player who fired the remote will always be passed as the first argument to the .OnServerEvent function, the second argument will be any arguments passed to :FireServer.

Oh okay so do I just put it like this?
image

Yeah, that looks good to me, just ensure you remove the player when you go to fire the server as well:

image
I got an error, I’ll send the code again I’m pretty sure I did everything right. I may be wrong…

Server Script:

local ProximityPrompt = script.Parent
local DialogueRemote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("DialougeRemote")
local MainModule = require(game.ServerScriptService.MainModule)


ProximityPrompt.Triggered:Connect(function(player)
	DialogueRemote:FireClient(player, "Would ya like to buy some of my fine crafted leather wear?", "Xalvador", "Alright! Have a look.") --Arguements sending to the local script.
	
	
end)


--CONNECT THE YEN AND FIRE TO THE CLIENT 

DialogueRemote.OnServerEvent:Connect(function(player, Data)
	
	--Clothing
	local ClothesFolder = game.Workspace.Shop.Clothes
	local ClotheModel1ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel1").Shirt.ShirtTemplate
	local ClotheModel2ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel2").Shirt.ShirtTemplate
	local ClotheModel3ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel3").Shirt.ShirtTemplate

	local ClotheModel1PantsTemplate = ClothesFolder:WaitForChild("ClotheModel1").Pants.PantsTemplate
	local ClotheModel2PantsTemplate = ClothesFolder:WaitForChild("ClotheModel2").Pants.PantsTemplate
	local ClotheModel3PantsTemplate = ClothesFolder:WaitForChild("ClotheModel3").Pants.PantsTemplate
	local Player = game:GetService("Players")
	local Char = player.Character
	local Stat = MainModule.GetStats(Char)
	local Yen = Stat.Yen
	
	if Data.Outcome == "Checking" then
		if Yen.Value < 50 then 
			local Data = { Outcome = "Invalid"}
			DialogueRemote:FireClient(Data)
			
		elseif Yen.Value >= 50 then
			local Data = { Outcome = "Valid"}
			DialogueRemote:FireClient(Data)
			
 		end
	end
	end)

Local script:

ClickDetector1.MouseClick:Connect(function(player)
		stepped:Disconnect()
		
		--Variables
	
		local goal = {CFrame = ClotheCam1.CFrame}
		local ClotheCam1Tween = tweenservice:Create(Camera, info, goal)
		
		-- Coding
		
		ClotheCam1Tween:Play()
		BuyGui.Enabled = true
		BuyGuiTweenCreated:Play()
		
		BuyGuiFrame:WaitForChild("Clothing Name").Text = "Firebending Robe"
		BuyGuiFrame:WaitForChild("Cost").Text = "50"
		
		LeftClickToBuy.MouseButton1Click:Connect(function()
			--Need to make some CharacterAdded function
				
				
				local data = {Outcome = "Checking"}
				Dialogueremote:FireServer(data)
			
			Dialogueremote.OnClientEvent:Connect(function(Data)
				
				if Data.Outcome == "Invalid" then 
					BuyGuiFrame:WaitForChild("Cost").Text = "Invalid Funds"
					
				elseif Data.Outcome == "Valid" then
					BuyGuiFrame:WaitForChild("Cost").Text = "Successfully Purchased!"
				end
				
			end)
				

You still need to pass the player to FireClient. It’s just omitted from the client-sided methods and events (FireServer and .OnClientEvent).

I the player variable after the data and its still giving me an error…


You need to pass the player first to :FireClient, you don’t need the player at all on the .OnClientEvent

It may be because im firing the remote twice in the server

Alright ima try to fix it right now.

1 Like

Okay So I also used the OnclientEvent on the remote to do the NPC talking stuff, do I use a different remote? I think the script is confused on which onclientevent it should respond to.

image

I’ll just send the whole local script so you can see it

local Dialogueremote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("DialougeRemote")
local userinputservice = game:GetService("UserInputService")
local tweenservice = game:GetService("TweenService")
local Camera = game.Workspace.CurrentCamera
local CameraFolder = game.Workspace:WaitForChild("Shop"):WaitForChild("ShopCameras")
local Camera1 = CameraFolder:WaitForChild("Camera1")
local Camera2 = CameraFolder:WaitForChild("Camera2")
local BlackGui= script.Parent:WaitForChild("BlackGui")
local BlackFrame = BlackGui:WaitForChild("Frame")
local BuyGui = script.Parent:WaitForChild("BuyGui")
local BuyGuiFrame = BuyGui:WaitForChild("Display")
local ClothesFolder = game.Workspace.Shop.Clothes
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local leaveGui = script.Parent:WaitForChild("LeaveGui")
local runservice = game:GetService("RunService")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local YesButtonConnect, LeaveButtonConnect, NoButtonConnect
local stepped
local maxTilt = 10

--CameraStuff
function CameraMoving(ShopCamera)

	--// Variables

	--// Move cam

	stepped = runservice.RenderStepped:Connect(function()
		Camera.CFrame = ShopCamera.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)
	


end


function TweenFrame(BlackFrame)
	
	
	
	local info = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false ,0)
	local info2 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
	
	local goal = {BackgroundTransparency = 0}
	local goal2 = {BackgroundTransparency = 1}
	
	local TweenCreated = tweenservice:Create(BlackFrame, info, goal)
	local TweenCreated2 = tweenservice:Create(BlackFrame, info, goal2)
	
	BlackGui.Enabled = true
	TweenCreated:Play()
	task.wait(1.5)
	TweenCreated2:Play()

end

function ShopClotheCamTween()
	--Variables
	local Char = game:GetService("Players").LocalPlayer.Character
	local LeftClickToBuy = script.Parent:WaitForChild("BuyGui"):WaitForChild("Display"):WaitForChild("Left click to buy")
	--TweenStuff

	
	
	--CAMERAS
	local ClotheCam1 = CameraFolder:WaitForChild("ClotheCam1")
	local ClotheCam2 = CameraFolder:WaitForChild("ClotheCam2")
	local ClotheCam3 = CameraFolder:WaitForChild("ClotheCam3")
	
	--CLOTHES
	local ClickPart1 = ClothesFolder:WaitForChild("Clothe1")
	local ClickPart2 = ClothesFolder:WaitForChild("Clothe2")
	local ClickPart3 = ClothesFolder:WaitForChild("Clothe3")
	
	local ClotheModel1ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel1").Shirt.ShirtTemplate
	local ClotheModel2ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel2").Shirt.ShirtTemplate
	local ClotheModel3ShirtTemplate = ClothesFolder:WaitForChild("ClotheModel3").Shirt.ShirtTemplate
	
	local ClotheModel1PantsTemplate = ClothesFolder:WaitForChild("ClotheModel1").Pants.PantsTemplate
	local ClotheModel2PantsTemplate = ClothesFolder:WaitForChild("ClotheModel2").Pants.PantsTemplate
	local ClotheModel3PantsTemplate = ClothesFolder:WaitForChild("ClotheModel3").Pants.PantsTemplate
	
	---CLICKDETECTORS
	local ClickDetector1 = Instance.new("ClickDetector")
	ClickDetector1.Name = "ClickDetector1"
	ClickDetector1.Parent = ClickPart1

	local ClickDetector2 = Instance.new("ClickDetector")
	ClickDetector2.Name = "ClickDetector2"
	ClickDetector2.Parent = ClickPart2

	local ClickDetector3 = Instance.new("ClickDetector")
	ClickDetector3.Name = "ClickDetector3"
	ClickDetector3.Parent = ClickPart3
	
	local info = TweenInfo.new(1,Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0)
	local BuyGuiGoal = {Visible = true}

	local BuyGuiTweenCreated = tweenservice:Create(BuyGuiFrame, info, BuyGuiGoal)
	
	ClickDetector1.MouseClick:Connect(function(player)
		stepped:Disconnect()
		
		--Variables
	
		local goal = {CFrame = ClotheCam1.CFrame}
		local ClotheCam1Tween = tweenservice:Create(Camera, info, goal)
		
		-- Coding
		
		ClotheCam1Tween:Play()
		BuyGui.Enabled = true
		BuyGuiTweenCreated:Play()
		
		BuyGuiFrame:WaitForChild("Clothing Name").Text = "Firebending Robe"
		BuyGuiFrame:WaitForChild("Cost").Text = "50"
		
		LeftClickToBuy.MouseButton1Click:Connect(function()
			--Need to make some CharacterAdded function
				
				
				local data = {Outcome = "Checking"}
				Dialogueremote:FireServer(data)
			
			Dialogueremote.OnClientEvent:Connect(function(Data)
				
				if Data.Outcome == "Invalid" then 
					BuyGuiFrame:WaitForChild("Cost").Text = "Invalid Funds"
					
				elseif Data.Outcome == "Valid" then
					BuyGuiFrame:WaitForChild("Cost").Text = "Successfully Purchased!"
				end
				
			end)
				

		
			
		end)
		
	end)

	ClickDetector2.MouseClick:Connect(function(player)
		stepped:Disconnect()
		

		local goal = {CFrame = ClotheCam2.CFrame}

		local ClotheCam2Tween = tweenservice:Create(Camera, info, goal)
		ClotheCam2Tween:Play()
		BuyGui.Enabled = true
		BuyGuiTweenCreated:Play()
		
		BuyGuiFrame:WaitForChild("Clothing Name").Text = "Firebending Kimono"
		BuyGuiFrame:WaitForChild("Cost").Text = "75"
		
		LeftClickToBuy.MouseButton1Click:Connect(function()
			--Need to make some CharacterAdded function
			local Data = {Clothing = "Clothing2"}
		


		end)
	end)

	ClickDetector3.MouseClick:Connect(function(player)
		stepped:Disconnect()
		

		local goal = {CFrame = ClotheCam3.CFrame}

		local ClotheCam3Tween = tweenservice:Create(Camera, info, goal)
		ClotheCam3Tween:Play()
		BuyGuiTweenCreated:Play()
		BuyGui.Enabled = true
		
		BuyGuiFrame:WaitForChild("Clothing Name").Text = "Firebending Red"
		BuyGuiFrame:WaitForChild("Cost").Text = "100"
		
		--[[Char.Shirt.ShirtTemplate = ClotheModel3ShirtTemplate
		Char.Pants.PantsTemplate = ClotheModel3PantsTemplate]]
	
		LeftClickToBuy.MouseButton1Click:Connect(function()
			--Need to make some CharacterAdded function
			local Data = {Clothing = "Clothing3"}
			


		end)
	end)
end

Dialogueremote.OnClientEvent:Connect(function(dialogue, personName, YesAnswer) -- Arguements that have been sent through server script.
	local proximityPrompt = game.Workspace:WaitForChild("Shop"):WaitForChild("ShopTender"):WaitForChild("UpperTorso"):WaitForChild("ProximityPrompt")
	proximityPrompt.Enabled = false
	local Gui = script.Parent
	Gui.Enabled = true
	
	repeat Camera.CameraType = Enum.CameraType.Scriptable until
	Camera.CameraType == Enum.CameraType.Scriptable
	Camera.CFrame = Camera1.CFrame
	CameraMoving(Camera1)
	
	local NpcText = Gui:WaitForChild("NpcText")
	
	NpcText.Text = dialogue
	local PersonNamed = Gui.NpcText:WaitForChild("PersonName")
	
	PersonNamed.Text = personName
	
	local Yes =Gui:WaitForChild("NpcText"):WaitForChild("Yes")
	local No = Gui:WaitForChild("NpcText"):WaitForChild("No")
	local leave = Gui:WaitForChild("LeaveGui"):WaitForChild("Leave")
	
	Yes.Visible = true
	No.Visible = true
	
	
	NoButtonConnect = No.MouseButton1Click:Connect(function()
		Gui.Enabled = false
		stepped:Disconnect()
		repeat Camera.CameraType = Enum.CameraType.Custom until
		Camera.CameraType == Enum.CameraType.Custom
		proximityPrompt.Enabled = true
		YesButtonConnect:Disconnect()

		NoButtonConnect:Disconnect()
		stepped:Disconnect()
		BuyGui.Enabled = false
	end)
	
	YesButtonConnect = Yes.MouseButton1Click:Connect(function()
	

		Gui.Enabled = false
		No.Visible = false
		Yes.Visible = false
		leave.Visible = true
		
		NpcText.Text = YesAnswer
		task.wait(1)
		TweenFrame(BlackFrame)
		stepped:Disconnect()
		
		repeat Camera.CameraType = Enum.CameraType.Scriptable until
		Camera.CameraType == Enum.CameraType.Scriptable
		Camera.CFrame = Camera2.CFrame
		
		stepped = runservice.RenderStepped:Connect(function()
			Camera.CFrame = Camera2.CFrame * CFrame.Angles(
				math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
				math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
				0
			)
			
		end)
		
		task.wait()
		leaveGui.Enabled = true
		task.wait(0.7)
		ShopClotheCamTween()
		
		
		
			 LeaveButtonConnect = leave.MouseButton1Click:Connect(function()
				Gui.Enabled = false
				leaveGui.Enabled = false
				stepped:Disconnect()
				repeat Camera.CameraType = Enum.CameraType.Custom until
				Camera.CameraType == Enum.CameraType.Custom
				proximityPrompt.Enabled = true
			local ClotheCam1 = ClothesFolder:WaitForChild("Clothe1"):FindFirstChild("ClickDetector1"):Destroy()
			local ClotheCam2 = ClothesFolder:WaitForChild("Clothe2"):FindFirstChild("ClickDetector2"):Destroy()
			local ClotheCam3 = ClothesFolder:WaitForChild("Clothe3"):FindFirstChild("ClickDetector3"):Destroy()
			YesButtonConnect:Disconnect()
			LeaveButtonConnect:Disconnect()
			NoButtonConnect:Disconnect()
			BuyGui.Enabled = false
			end)
			end)
			
	end)

Yeah, you should use two different remotes if they need to have separate functionalities.

Ok Im gonna do that right now.

1 Like

Okay! I got it working. Thanks so much for your help. I do have to ask though why did I have to put the player after the table?

Essentially when you call FireClient, it expects the first argument to be the player whose client the remote is firing. Then it expects any arguments after that to be the actual data to be sent. So,
On the server: event:FireClient(player, data…) → on client: event.OnClientEvent(data…)

However when firing the server and receiving the event on the server, the data gets moved over and the player is first, so:
Client: event:FireServer(data…) → on the server: event.OnServerEvent(playerWhoFired, data…)

1 Like

Ooh I thought you had to do Player, data to stay consistent because the script will think data is the player because it’s the first arguement

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.