So in the server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
Event:FireAllClients()
In the client script
local Button = script.Parent
local MainFrame = script.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
local Cookie = ReplicatedStorage:WaitForChild("Cookie")
local Proximity = game.Workspace:WaitForChild("Plate").Proximity
Button.MouseButton1Click:Connect(function()
MainFrame.Visible = false
Event.OnClientEvent:Connect(function(Player)
local Clone = Cookie:Clone()
Clone.Parent = game.Workspace
Clone.Anchored = false
Clone.Position = Proximity.Position
end)
end)
The issue is, the cookie is not cloning.
There are also no errors in the output.
I think it’s because you have the OnClientEvent
inside of the MouseButton1Click
. I would move OnClientEvent
out of the function
okay. I will try to do that.
Empty space.
It breaks the script…
I think it’s because it does not know what the on client event is.
Try this:
local Button = script.Parent
local MainFrame = script.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
local Cookie = ReplicatedStorage:WaitForChild("Cookie")
local Proximity = game.Workspace:WaitForChild("Plate").Proximity
Button.MouseButton1Click:Connect(function()
MainFrame.Visible = false
end)
Event.OnClientEvent:Connect(function(Player)
local Clone = Cookie:Clone()
Clone.Parent = game.Workspace
Clone.Anchored = false
Clone.Position = Proximity.Position
end)
that does not work either.
blank space
Do you know the error that is printed out in the output?
You have a “player” parameter inside of the event function. However you didn’t pass anything through the event inside the script. Adding to this, you don’t have a player parameter inside of a OnClientEvent function, unless you specifically passed one through while firing the event.
So you should remove the “Player” parameter inside of the OnClientEvent.
FireClient takes a mandatory player object, so instead of removing the player parameter, his server script should be change to:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
game.Players.PlayerAdded:Connect(function(player)
Event:FireClient(player)
end)
FireAllClients does not have a player object, because it fires for all clients…
I think you have to replace “FireAllClients” with “FireClient” else it will fire all the clients every time a player joins + you can’t do FireAllClients(Player)
there are no errors in the output.
i tried that and it still does not work.
Have you checked if the event fires?