#Issue with lag duplicated dogs
1 messages · Page 1 of 1 (latest)
can you send the server script and the part where you call the onClick()
sure
AddDogFunction.OnServerInvoke = function(player, dogType, pen, position, rotation)
local plot = nil
if player:FindFirstChild("Plot") and player.Plot.Value then
plot = player.Plot.Value
else
SendNotification:FireClient(player, "❌ You don't have a plot!")
return nil
end
if pen.Parent ~= plot then
SendNotification:FireClient(player, "❌ Invalid pen: " .. tostring(pen))
return nil
end
local PlotDogs = pen:WaitForChild("Dogs")
local zone = pen:WaitForChild("Zone")
local dogTemplate = dogTemplateFold:FindFirstChild(dogType or "Basic")
if not dogTemplate then
SendNotification:FireClient(player, "❌ Invalid dog type: " .. tostring(dogType))
return nil
end
local dog = dogTemplate:Clone()
dog.Parent = workspace
local root = dog:WaitForChild("HumanoidRootPart")
its really long but im pretty sure this is all we need to debug it
or ig not really a bug
but idk what check to do
just to check - did you spam click the tool and that caused 30 dogs to spawn, or did you only click once during lag and still got 30?
if i knew how to do this I wouldnt be here 😭


could you explain what happened in a bit more detail, what you did, what it was supposed to do and what happened instead?
If it's only supposed to spawn one dog after clicking multiple times I assume the reason why you're getting more dogs is because you're checking if you already spawned one in the local script instead of the server one. This means that you can invoke the server multiple times before the first pcall even returns a result
basically, you go and buy a dog from the shop, u get the dog in your inventory, you hold the dog out, you place to click it, and it spawns and deletes it from your inventory
but while i was lagging I clicked multiple times with the tool out sense it didnt spawn because I was lagging, and then 30 dogs spawned
because I spammed it
try adding debounce so that multiple functions can't run at the same time
local db = false
function onClick()
if db then return end
db = true
--your code
end
--when you call the function wait for it to finish running before letting another one run
tool.Activated:Connect(function()
if db then return end
onClick()
db = false
end)
something like this
ok i gotta wait for my next lag spike to test it
try adding a wait(2) in the pcall before invoking the server to mimic the lag
or just add a wait() at the beginning of the server function
np
yes
hmm then whats the point of the on clicked
is there a difference between using activated
how were you calling it then?
it's similar, but the tool.activated is easier to use, it fires whenever you left click with a tool equipped
oh wait i remember
I used the input because I wanted it to place when the palyer let go
just had a lag spike and it worked
yay
use tool.deactivated then
nice
either way it works now thahks for the help :D
np
@chrome pasture
I dont know if i didnt notice this at the time
but it sits there for like 3 seconds now before placing the dog
and idk why
Remove the wait
Did you place a wait in the server script as well?
i did but i took it out
should i send you the script im really lost
wait holy cow
why do i keep doing this
im so sorry for pinging u i keep making thi same stupid mistake
basically i duplicate the tool into starter pack to test it
but i edit the original tool script
and so it doesnt update the start pack one
Lol its fine dw
god this is the 5th time that ive made that mistake and been completely confused for 20 mins 😆
You should probably make a tool handler kind of script for the client
Its way cleaner and easier to manage since you have all your code in one script
I can show you an example tmr when I wake up if you're interested