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

Why RemoteEvent is taking my player instead of taking what is in FireServer?

--------------------------
--Script(ServerScriptService)
local money = game:GetService("ServerStorage"):WaitForChild("PlayerMoney")
local event = game:GetService("ReplicatedStorage").Events.CashGui

event.OnServerEvent:Connect(function(PlayerText, Cash)
	money[PlayerText.Text].Value = money[PlayerText.Text].Value + Cash.Text
end)
--------------------------


-- LocalScript(gui)

local plr = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage").Events.CashGui
local money = game:GetService("ServerStorage"):WaitForChild("PlayerMoney")
local Send = script.Parent.GiveCash

function Smart()
	local PlayerText = script.Parent.PlayerText
	local Cash = script.Parent.CashText
	local plr = game:GetService("Players"):FindFirstChild(PlayerText.Text)
	if plr then
	event:FireServer(PlayerText, Cash)
	else
		print(PlayerText.Text.. " is Offline.")
	end
end
Send.MouseButton1Click:Connect(Smart)

Error:

--Text is not a valid member of Player

-- Script 'ServerScriptService.CashGUi', Line 6

1 answer

✓ Accepted answer

The problem is that when you fire a remote event, you will always instantly receive a parameter for the player, no matter if you provide it as an argument or not. Therefore the roblox server is regarding your first parameter as the player and is causing your script to error. Here is the line you need to fix to make it work.

--Straight to line 6
event.OnServerEvent:Connect(function(player, PlayerText, Cash) --Change line 6 to this line and your script will be working just fine.

6 comments

0

Weird, should've worked :/

0

Did you change anything?

0

How strange, I had already tried it and it made a mistake and now it worked.

0

Other than the line I told you

0

Oh brilliant, have a nice day then :)

0

I went for a look at LocalScript and it was FireServer (plr, Cash) dizzy

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