Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago
--------------------------
--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

Log in to vote
1
Answered by 5 years ago

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.
0
Weird, should've worked :/ MaximumOverdriven 152 — 5y
0
Did you change anything? MaximumOverdriven 152 — 5y
0
How strange, I had already tried it and it made a mistake and now it worked. ToddyWars 41 — 5y
0
Other than the line I told you MaximumOverdriven 152 — 5y
View all comments (2 more)
0
Oh brilliant, have a nice day then :) MaximumOverdriven 152 — 5y
0
I went for a look at LocalScript and it was FireServer (plr, Cash) dizzy ToddyWars 41 — 5y
Ad

Answer this question