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:
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)
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.
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)
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.
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…)