I have a remote event in Replicated storage that I need fired, and used in another script. However, the event won’t fire, idk why. can someone help?
Here are the two scripts
script.Parent.Touched:Connect(function(Hit)
if Hit and Hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.SpawnChick:FireServer()
end
end)
local SpawnName = game.ReplicatedStorage:FindFirstChild("ChickenL4")
local S = script.Parent.Chicken
local Spaw = game.ReplicatedStorage.SpawnChick
local chicken = game.ReplicatedStorage.ChickenL4
Spaw.OnServerEvent:Connect(function()
chicken:clone()
chicken.Parent = game.Workspace
chicken.Position = script.Parent.Position
S:Play()
print("Spawned!")
end)
Assuming this part is in the workspace, and since you are using FireClient, Im guessing this script is inside of a LocalScript. LocalScripts cant run in the workspace, they can only work on the players Character (i forgot the name but things that :SetNetworkOwnership() is on), PlayerGui, StarterPlayer/Character, Backpack, etc. They cant run in workspace which is why your event isnt firing
@joshuaThe5th
You dont need a RemoteEvent for this, you can just use a standard Script:
To point out One of your Errors:
You Aren’t specifying what the Chicken Clone is, you are setting the real chicken object to the workspace instead of the clone
Possible fix:
local SpawnName = game.ReplicatedStorage:FindFirstChild("ChickenL4")
local S = script.Parent.Chicken
local Spaw = game.ReplicatedStorage.SpawnChick
local chicken = game.ReplicatedStorage.ChickenL4
local function SpawnChicken()
local C = chicken:clone()
C.Parent = workspace
C.Position = script.Parent.Position
S:Play()
print("Spawned!")
end
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
SpawnChicken()
end
end)
It appears that you are using a RemoteEvent to connect 2 Server scripts. I would recommend just placing the .Touched function inside of the other script that spawns chickens. The alternative would just be to use a Bindable Event to connect the 2 scripts.
local SpawnChick = game:GetService("ReplicatedStorage"):WaitForChild("SpawnChick")
script.Parent.Touched:Connect(function(Hit)
if Hit and Hit.Parent:FindFirstChild("Humanoid") then
SpawnChick:FireServer()
end
end)
--local SpawnName = game.ReplicatedStorage:FindFirstChild("ChickenL4") ???
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local S = script.Parent.Chicken
local Spaw = ReplicatedStorage:WaitForChild("SpawnChick")
local chicken = ReplicatedStorage:WaitForChild("ChickenL4")
Spaw.OnServerEvent:Connect(function()
chicken:clone()
chicken.Parent = game.Workspace
chicken.Position = script.Parent.Position
S:Play()
print("Spawned!")
end)