#Fires twice

1 messages · Page 1 of 1 (latest)

open yoke
#

I have a script that is aimed at tracking touch, but when touching an object, the action for some reason works twice

other part of script only spawn a part

  local Currency = Stat.Get(Player, "Money")
  local Rebirth = Stat.Get(Player, "Rebirth")

  NewPart.Touched:Connect(function(Hit)
    if Hit.Name == "Furnace" then
      Currency.Value += Worth.Value * Multipliers.GetMoneyMultiplier(Player)
      NewPart:Destroy()
      print(Currency.Value)
    elseif Hit.Name == "Ground" then
      NewPart:Destroy()
    end
  end)
end

Output:
03:47:52.427 718 - Server - Dropper:37
03:47:55.893 383 - Server - Orer:37
03:47:56.643 720 - Server - Dropper:37--
03:47:56.643 722 - Server - Dropper:37--
03:48:00.210 384 - Server - Orer:37
03:48:00.943 724 - Server - Dropper:37
03:48:04.310 385 - Server - Orer:37
03:48:05.109 726 - Server - Dropper:37
03:48:08.609 386 - Server - Orer:37
03:48:09.293 728 - Server - Dropper:37
03:48:12.892 387 - Server - Orer:37
03:48:13.543 730 - Server - Dropper:37--
03:48:13.543 732 - Server - Dropper:37--
03:48:16.959 388 - Server - Orer:37

chrome shell
#

newpart.touched:connect(function(hit)
  if touchedonce then return end
  touchedonce = true

end)
#

basically

open yoke
chrome shell
#

show the full script

#

@open yoke

open yoke
#
local Dropper = {}

local Stat = require(game.ReplicatedStorage.Stat)
local Multipliers = require(game.ReplicatedStorage.Multipliers)

function Dropper.Spawn(Player, Pos, Amount)
    local NewPart = game.ReplicatedStorage.SellBlock.CoalBlock:Clone()
    NewPart.Size = Vector3.new(3,3,3)
    NewPart.Position = Pos
    NewPart.Parent = workspace.DropperParts[Player.Name.."-DropperParts"]

    local Worth = Instance.new("NumberValue")
    Worth.Name = "Worth"
    Worth.Value = Amount
    Worth.Parent = NewPart

    local Billboard = script.BillboardGui:Clone()
    Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    Billboard.Parent = NewPart

    Worth.Changed:Connect(function()
        Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    end)

    task.spawn(function() -- Despawn after 30 seconds
        task.wait(30)
        NewPart:Destroy()
    end)

    local Currency = Stat.Get(Player, "Money")
    local Rebirth = Stat.Get(Player, "Rebirth")

    local touchedonce = false

    NewPart.touched:connect(function(Hit)
        if touchedonce then return end
        touchedonce = true
        if Hit.Name == "Furnace" then
            Currency.Value += Worth.Value * Multipliers.GetMoneyMultiplier(Player)
            NewPart:Destroy()
            print(Currency.Value)
            touchedonce = true
        elseif Hit.Name == "Ground" then
            NewPart:Destroy()
            touchedonce = true
        end
    end)
end

return Dropper
chrome shell
#

move touched once variable

#

to the top of ur script

#

wait no

#

im dumb

#

delete the touchedonce = true at the elseif hit.name = ground

#

and the one under the print

open yoke
chrome shell
#

what was ur problem exactly again

#

.touched running multiple times

#

right

open yoke
#

yes

#

6:26:39.986 17 - Server - Orer:37
16:26:43.236 18 - Server - Dropper:37
16:26:43.236 19 - Server - Dropper:37
16:26:44.137 18 - Server - Orer:37

chrome shell
#

r u sure u did what i asked that should've fixed it

open yoke
chrome shell
#

show me the other script

open yoke
#
local Dropper = {}

local Stat = require(game.ReplicatedStorage.Stat)
local Multipliers = require(game.ReplicatedStorage.Multipliers)

function Dropper.Spawn(Player, Pos, Amount)
    local NewPart = game.ReplicatedStorage.SellBlock.CoalBlock:Clone()
    NewPart.Size = Vector3.new(3,3,3)
    NewPart.Position = Pos
    NewPart.Parent = workspace.DropperParts[Player.Name.."-DropperParts"]

    local Worth = Instance.new("NumberValue")
    Worth.Name = "Worth"
    Worth.Value = Amount
    Worth.Parent = NewPart

    local Billboard = script.BillboardGui:Clone()
    Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    Billboard.Parent = NewPart

    Worth.Changed:Connect(function()
        Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    end)

    task.spawn(function() -- Despawn after 30 seconds
        task.wait(30)
        NewPart:Destroy()
    end)

    local Currency = Stat.Get(Player, "Money")
    local Rebirth = Stat.Get(Player, "Rebirth")

    local touchedonce = false

    NewPart.touched:connect(function(Hit)
        if touchedonce then return end
        touchedonce = true
        if Hit.Name == "Furnace" then
            Currency.Value += Worth.Value * Multipliers.GetMoneyMultiplier(Player)
            NewPart:Destroy()
            print(Currency.Value)
        elseif Hit.Name == "Ground" then
            NewPart:Destroy()
        end
    end)
end

return Dropper
chrome shell
#

that's the same script u js showed me

#

there's 2 scripts in uroutput

#

"orer" and dropper

open yoke
#

it's 2 same scrips

safe breachBOT
#

studio** You are now Level 1! **studio

chrome shell
#

well then obviously ur going to get

#

.touched twice

#

😭

open yoke
#

i renamed second to understand when it is fires twice

chrome shell
#

oh each one is happening twice

#

is that the issue

open yoke
#

they also have different values in Stat.Get

chrome shell
#

try doing a disconnect

#

hold on

#
local Dropper = {}

local Stat = require(game.ReplicatedStorage.Stat)
local Multipliers = require(game.ReplicatedStorage.Multipliers)

function Dropper.Spawn(Player, Pos, Amount)
    local NewPart = game.ReplicatedStorage.SellBlock.CoalBlock:Clone()
    NewPart.Size = Vector3.new(3,3,3)
    NewPart.Position = Pos
    NewPart.Parent = workspace.DropperParts[Player.Name.."-DropperParts"]

    local Worth = Instance.new("NumberValue")
    Worth.Name = "Worth"
    Worth.Value = Amount
    Worth.Parent = NewPart

    local Billboard = script.BillboardGui:Clone()
    Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    Billboard.Parent = NewPart

    Worth.Changed:Connect(function()
        Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    end)

    task.spawn(function() -- Despawn after 30 seconds
        task.wait(30)
        NewPart:Destroy()
    end)

    local Currency = Stat.Get(Player, "Money")
    local Rebirth = Stat.Get(Player, "Rebirth")

   local connection = NewPart.touched:Connect(function(Hit)
             connection:Disconnect()
        if Hit.Name == "Furnace" then
            Currency.Value += Worth.Value * Multipliers.GetMoneyMultiplier(Player)
            NewPart:Destroy()
            print(Currency.Value)
        elseif Hit.Name == "Ground" then
            NewPart:Destroy()
        end
    end)
end

return Dropper
safe breachBOT
#

studio** You are now Level 8! **studio

chrome shell
#

try that

#

oh also

#

it's :Connect()

#

hold on

#

ok try that

chrome shell
#

ye i'm lost dawg

#

dis is simple territory ion see wat could b wrong

#
local Stat = require(game.ReplicatedStorage.Stat)
local Multipliers = require(game.ReplicatedStorage.Multipliers)

function Dropper.Spawn(Player, Pos, Amount)
    local NewPart = game.ReplicatedStorage.SellBlock.CoalBlock:Clone()
    NewPart.Size = Vector3.new(3,3,3)
    NewPart.Position = Pos
    NewPart.Parent = workspace.DropperParts[Player.Name.."-DropperParts"]
    
    local Worth = Instance.new("NumberValue")
    Worth.Name = "Worth"
    Worth.Value = Amount
    Worth.Parent = NewPart
    
    local Billboard = script.BillboardGui:Clone()
    Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    Billboard.Parent = NewPart
    
    Worth.Changed:Connect(function()
        Billboard.TextLabel.Text = "$"..Worth.Value * Multipliers.GetMoneyMultiplier(Player)
    end)
    
    task.spawn(function() -- Despawn after 30 seconds
        task.wait(30)
        NewPart:Destroy()
    end)
    
    local Currency = Stat.Get(Player, "Money")
    local Rebirth = Stat.Get(Player, "Rebirth")
    
    local connection
    connection = NewPart.Touched:Connect(function(Hit)
        if Hit.Name == "Furnace" then
            Currency.Value += Worth.Value * Multipliers.GetMoneyMultiplier(Player)
            NewPart:Destroy()
            print(Currency.Value)
            connection:Disconnect()
        elseif Hit.Name == "Ground" then
            NewPart:Destroy()
            connection:Disconnect()
        end
    end)
end 

return Dropper```
#

try that n if that don't work i'm at a loss