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
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
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!