Hey, are you trying to clone the cookie only for the client’s side or do you want this server side?
If you want it only client sided then you don’t need to do the .OnClientEvent:, just do this
local Button = script.Parent
local MainFrame = script.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cookie = ReplicatedStorage:WaitForChild("Cookie")
local Proximity = game.Workspace:WaitForChild("Plate").Proximity
Button.MouseButton1Click:Connect(function()
MainFrame.Visible = false
local Clone = Cookie:Clone()
Clone.Parent = game.Workspace
Clone.Anchored = false
Clone.Position = Proximity.Position
end)
But if you are trying to do it on the server side then do this instead:
-- Local Script
local Button = script.Parent
local MainFrame = script.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
Button.MouseButton1Click:Connect(function()
MainFrame.Visible = false
Event:FireServer()
end)
-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("CookieEvent")
local Cookie = ReplicatedStorage:WaitForChild("Cookie")
local Proximity = game.Workspace:WaitForChild("Plate").Proximity
Event.OnServerEvent:Connect(function()
local Clone = Cookie:Clone()
Clone.Parent = game.Workspace
Clone.Anchored = false
Clone.Position = Proximity.Position
end)
local Button = script.Parent
local Cookie = ReplicatedStorage:WaitForChild("Cookie")
local loopId = 0
local looping = false
local function StartLoop()
looping = true
loopId += 1
local id = loopId
while id == loopId do
print("Loop")
local Clone = Cookie:Clone()
Clone.Parent = game.Workspace
Clone.Anchored = false
Clone.Position = Proximity.Position
task.wait(1)
end
end
local function StopLoop()
looping = false
loopId += 1
end
Button.MouseButton1Click:Connect(function()
if looping = false then
StartLoop()
else
StopLoop()
end
end)