Hi, so I’m trying to make a painting system for my game. However, when I fireserver() to do the event I’ve used from the client side it fires like 100 times and lags the hell out of my game. I’m unsure why this is firing so much times.
local deb = false
mouse.Button1Down:Connect(function()
if not deb then
deb = true
task.wait()
event:FireServer(mouse.Target, game.Players.LocalPlayer)
end
end)
local u = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local event = game.ReplicatedStorage.PaintPart
u.InputChanged:Connect(function(int)
if m.Target then
if m.Target.Name == "WorldPiece" then
local deb = false
m.Button1Down:Connect(function()
if not deb then
deb = true
event:FireServer(m.Target, game.Players.LocalPlayer)
end
end)
end
end
end)
-- Server Main
local event = game.ReplicatedStorage.PaintPart
game.Players.PlayerAdded:Connect(function(plr)
local val = Instance.new('BrickColorValue')
val.Parent = plr
val.Value = BrickColor.new('White')
val.Name = "Colour"
end)
event.OnServerEvent:Connect(function(part, plr)
plr.BrickColor = part.Colour.Value
print(part.Name.." has painted a part.")
end)
local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local event = game.ReplicatedStorage.PaintPart
m.Button1Down:Connect(function()
if m.Target then
if m.Target.Name == "WorldPiece" then
event:FireServer(m.Target, game.Players.LocalPlayer)
end
end
end)
(By the way, you dont need to send the player object through the remote event, it gets passed automatically. So with how you are firing the event right now the server will see the arguments as player, target, player)