What’s the code on the client? This is for the server and I don’t really see anything that would cause the issue. Perhaps the client is sending the request multiple times?
Besides that, I see other issues with your code…
workspace:FindFirstChild(spawnedcpu).screen.BrickColor = BrickColor.new(Really black)
workspace:FindFirstChild(spawnedcpu).screen.Material = Enum.Material.Plastic
can be shortened to this:
local item = workspace:FindFirstChild(spawnedcpu)
item.screen.BrickColor = BrickColor.new(Really black)
item.screen.Material = Enum.Material.Plastic
That way, you are only running functions once. It’s not much of a performance improvement, but on the server, every clock cycle counts. Then there is this code:
local teacher = rs:WaitForChild("block"):Clone()
teacher.Parent = workspace
local cframe = CFrame.new(mousepos)
teacher:SetPrimaryPartCFrame(cframe)
wait(0.5)
rs.enable:FireClient(player)
Always set the parent at the end. Setting it to the beginning will cause the server to replicate each change to all clients which means more work for the server which means more of a chance for lag. Here’s the new code:
local teacher = rs:WaitForChild("block"):Clone()
local cframe = CFrame.new(mousepos)
teacher:SetPrimaryPartCFrame(cframe)
teacher.Parent = workspace
wait(0.5)
rs.enable:FireClient(player)
I would also strongly recommend that you use a debounce in your code. What a debounce does is that is limits the rate of requests to the server so it doesn’t get bogged down so much. The general form of a debounce is this:
local debounce = false
some_function_definition(some_parameters)
if not debounce then
debounce = true
-- Do Something
delay(timeout, function()
debounce = false
end)
end
end
The delay function spawns a new thread that doesn’t start executing the nested function until the timeout has elapsed. This is the preferred way because it doesn’t hang up the thread context that the some_function is executing in.
So with the debounce, your code would look like this:
local on = false
rs:FindFirstChild("cce2").OnServerEvent:Connect(function(player,key)
workspace:FindFirstChild("spawnedcpu").screen.BrickColor = BrickColor.new("Really black")
workspace:FindFirstChild("spawnedcpu").screen.Material = Enum.Material.Plastic
rs.mouse:FireClient(player)
if not on then
on = true
rs:FindFirstChild("mouse").OnServerEvent:Connect(function(player,mousepos)
local teacher = rs:WaitForChild("block"):Clone()
local cframe = CFrame.new(mousepos)
teacher:SetPrimaryPartCFrame(cframe)
teacher.Parent = workspace
delay(0.5, function()
rs.enable:FireClient(player)
on = false
end)
end)
end
end)