Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Problem with script that worked correctly but only once time then it got break?

Asked by 4 years ago

Im OriginalDevelops, Im scripting a machine that player clicked and then it spawn a npc, then after a seconds the npc will automatic dead and be removed from the workspace, then the machine will be automatic refresh! This is my script ( normal script not local ) :

local ClickDetector = script.Parent.Detector
local part = script.Parent
local debounce = false

local NPCSpawn = script.Parent.Parent.SpawnPart
local NPC = game.ServerStorage.NPCs.Noob
local newMachine = game.ServerStorage.SpawnMachine

ClickDetector.MouseClick:Connect(function()
    if not debounce then
        debounce = true
        local cloneNoob = NPC:Clone()
        cloneNoob.Name = "Noob"
        cloneNoob.Parent = NPCSpawn
        part.SurfaceGui.TextLabel.Text = "Cooldown..."
        part.Color = Color3.fromRGB(255,0,0)
        wait(30)
        part.SurfaceGui.TextLabel.Text = "Spawn"
        part.Color = Color3.fromRGB(0,255,0)
        cloneNoob.Humanoid.Health = 0
        wait(10)
        cloneNoob:Destroy()
        print("Cooldown Completed!")
        local cloneMachine = newMachine:Clone()
        cloneMachine.Name = "SpawnMachine"
        cloneMachine.Parent = workspace
        print("New Machine Has Been Spawned!")
        wait(0.001)
        part.Parent:Destroy()
        print("Old Machine Has Been Destroyed!")
    end
end)

The issue is, all the machine is still working good but the machine can only be refresh once then the machine automatic disappered! The upper code still run, the npc still automatic get destroyed but the machine didnt get clone! That mean the upper code work infinity but the down code only worked once! Can anyone help me with this?

0
Do you ever set debounce to false? If not try setting debounce to false after line 30. techN0logics 40 — 4y
0
When I set that, the noob not being destroy or kill and the machine being cooldown forever OriginalDevelops 22 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
ClickDetector.MouseClick:Connect(function()
    if not debounce then
        debounce = true
        local cloneNoob = NPC:Clone()
        cloneNoob.Name = "Noob"
        cloneNoob.Parent = NPCSpawn
        part.SurfaceGui.TextLabel.Text = "Cooldown..."
        part.Color = Color3.fromRGB(255,0,0)
        wait(30)
        part.SurfaceGui.TextLabel.Text = "Spawn"
        part.Color = Color3.fromRGB(0,255,0)
        cloneNoob.Humanoid.Health = 0
        wait(10)
        cloneNoob:Destroy()
        print("Cooldown Completed!")
        local cloneMachine = newMachine:Clone()
        cloneMachine.Name = "SpawnMachine"
        cloneMachine.Parent = workspace
        print("New Machine Has Been Spawned!")
        wait(0.001)
        part.Parent:Destroy()
        print("Old Machine Has Been Destroyed!")
    end
    print("Clear to press")
    debounce = false
end)

Try that and don't spam the button just press it 1 time wait for it to print clear to press then click it again. Then go from there. I am not in studio so I can't test this but It should work.

0
Don't put that code on line 1 past it on line 9 and remove your old code keep all of the local stuff. Be sure to copy the code by clicking view source. techN0logics 40 — 4y
0
Local stuff i.e. lines 1-8. techN0logics 40 — 4y
0
In the 3rd time, the machine disappered forever OriginalDevelops 22 — 4y
0
Can you fix that? OriginalDevelops 22 — 4y
View all comments (2 more)
0
Tbh that's beyond my knowledge I just started scripting 4 days ago. That thing I told you has always worked for me. techN0logics 40 — 4y
0
nvm I just accpet your OriginalDevelops 22 — 4y
Ad

Answer this question