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)
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
-- 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.