#Issue with lag duplicated dogs

1 messages · Page 1 of 1 (latest)

cosmic temple
#

I discovered when i was lagging I spammed the tool that placed the dog down and it placed 30 dogs when you are only supposed to get one

chrome pasture
# cosmic temple

can you send the server script and the part where you call the onClick()

cosmic temple
#
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

chrome pasture
cosmic temple
chrome pasture
# cosmic temple 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

cosmic temple
#

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

chrome pasture
cosmic temple
#

ok i gotta wait for my next lag spike to test it

chrome pasture
#

or just add a wait() at the beginning of the server function

cosmic temple
#

ah i think it works now

#

thanks man!

chrome pasture
#

np

cosmic temple
#

btw what does the tool.activated even mean

#

is that when its clicked

chrome pasture
#

yes

cosmic temple
#

hmm then whats the point of the on clicked

#

is there a difference between using activated

chrome pasture
#

how were you calling it then?

cosmic temple
#

input

#

service

#

wait hold up

#

oh wait nvm

chrome pasture
# cosmic temple input

it's similar, but the tool.activated is easier to use, it fires whenever you left click with a tool equipped

cosmic temple
#

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

chrome pasture
chrome pasture
cosmic temple
#

either way it works now thahks for the help :D

chrome pasture
#

np

cosmic temple
#

@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

chrome pasture
#

Remove the wait

cosmic temple
#

i did

#

its really weird idk why this is hapening

chrome pasture
#

Did you place a wait in the server script as well?

cosmic temple
#

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

chrome pasture
cosmic temple
#

god this is the 5th time that ive made that mistake and been completely confused for 20 mins 😆

chrome pasture
#

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