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

01--Declare
02--GameServices
03local plr = game:GetService("Players").LocalPlayer
04local Workspace = game:GetService("Workspace")
05local repSto = game:GetService("ReplicatedStorage")
06 
07--Items
08local fooPic = script.Parent
09local AddValueEvent = repSto:WaitForChild("FoodPickupEvent")
10 
11--Process
12local function FireServerWhenTouched (hit, plr)
13    if hit.Parent:FindFirstChild("Humanoid") then
14        fooPic:Destroy()
15        AddValueEvent:FireClient(plr)
View all 50 lines...

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.

1local function FireServerWhenTouched (hit)
2    if hit.Parent:FindFirstChild("Humanoid") then
3        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
4        fooPic:Destroy()
5        AddValueEvent:FireClient(plr)
6    end
7end
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