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

Remote Event not working? Works in studio but not game

Asked by 6 years ago
Edited 6 years ago

I made an object with a server script inside, a remote event inside player character scripts, and a remote event inside replicated Storage. The thing works inside studio, but In-game it says Fireclient argument must be a player object. Any ideas? Thank you. this is server script

--Declare
--GameServices
local plr = game:GetService("Players").LocalPlayer
local Workspace = game:GetService("Workspace")
local repSto = game:GetService("ReplicatedStorage")

--Items
local fooPic = script.Parent
local AddValueEvent = repSto:WaitForChild("FoodPickupEvent")

--Process
local function FireServerWhenTouched (hit, plr)
    if hit.Parent:FindFirstChild("Humanoid") then
        fooPic:Destroy()
        AddValueEvent:FireClient(plr)
    end
end
--Conect
fooPic.Touched:Connect(FireServerWhenTouched)


--------------------------------------------------
this is local script inside player

--Declar
--GameServices
local player = game:GetService("Players").LocalPlayer
local pgui = player:WaitForChild("PlayerGui")
local repStore = game:GetService("ReplicatedStorage")

--RemoteEvent
local AddValueEvent = repStore:WaitForChild("FoodPickupEvent")

--PLayerGui
local sg = pgui:WaitForChild("ScreenGui")
local is = sg:WaitForChild("InStats")
local foodAmm = is:WaitForChild("FoodAmm")

local bp = player:WaitForChild("Backpack")
local isf = bp:WaitForChild("InvStats")
local accAmm = isf:WaitForChild("FoodAmm")

--Process
local function ChangeMessageWhenFired()
    accAmm.Value = (accAmm.Value + 1)
    foodAmm.Text = accAmm.Value
end

--Connect
AddValueEvent.OnClientEvent:Connect(ChangeMessageWhenFired)

thank you

0
oh my; the code block did not work ;( Zafirua 1348 — 6y
0
I fixed the code block lol TheFierceWaffle 64 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

The touch event is only passing in "hit". Your "plr" is then nil.

To get the player you have to find the character and then the player.


local function FireServerWhenTouched (hit) if hit.Parent:FindFirstChild("Humanoid") then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) fooPic:Destroy() AddValueEvent:FireClient(plr) end end
Ad
Log in to vote
1
Answered by 6 years ago

I was surfing your script and I immediately noticed a deadly error, you cannot call the "LocalPlayer" in a server script. It may only be called in a local script, on the client. Try fixing that and if it works, accept this answer. If not, please let me know any more errors by commenting down below. Thanks!

Answer this question