RemoteEvent not sending to server

I’m trying to make a special developer menu for a simulator game I’m making, but when I click on a button to give me a pet, it isn’t sending to the server.

My goal is to use a ServerScript to redirect the RemoteEvent back to the client for a different LocalScript.

There’s also no errors.

I also tried using pcall() to see if anything was going wrong, but pcall() just returns nil.

Here’s my code.

LocalScript

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
print("clicked")
local pet = game.ReplicatedStorage.Pets:FindFirstChild(script.Parent.Name)
print(pet)
pcall(function(success,Error)
game.ReplicatedStorage.AddPet:FireServer(plr,pet)
if success then
print("Sent")
else
print(Error)
end
end)

print("sent??")
end)

ServerScript

game.ReplicatedStorage:WaitForChild("AddPet").OnServerEvent:Connect(function(plr, pet)
print(plr,pet)
end)
1 Like

This probably isnt relevant but what is ‘error’?

That’s a part of pcall()
It’s to print the error message

I’ve done some reading, and it possibly could be malware scripts interfering.
I’ll have to check for anything suspicious in my game

Couldn’t find anything bad. Guess that’s not the problem?

Firstly there’s no need to wrap a remote event in a pcall, I don’t think anyway. So i would remove that completely. Also you should use :GetService() and define it once in the script its much better practice

Yeah, I know. I was trying to do that for debugging. I’ve removed it though

I tried putting a print() at the beginning of my script, and that didn’t show up.
I guess the ServerScript isn’t running?

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Remote
local AddPet = ReplicatedStorage:WaitForChild("AddPet")

-- Player instance
local Player = Players.LocalPlayer

-- Connections
script.Parent.Activated:Connect(function()
   AddPet:FireServer(script.Parent.Name)
end)

-- Server Script

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Remote
local AddPet = ReplicatedStorage:WaitForChild("AddPet")

-- Events
AddPet.OnServerEvent:Connect(function(player: Player, petName: string)
   -- Add some sanity checks
   local Pet = ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(petName)
end)

Hope this helps, I think the error is your sending player over the event when it already does that.

Found the problem! I accidentally put my script in ServerStorage, not ServerScriptService.
Oops.

1 Like