#Remote events increments firing +1 for no reason

1 messages · Page 1 of 1 (latest)

vivid wagon
#

okay ill explain better here

-player clicks shop item

-shop item is set to 10 coins

-script inside serverscriptservice fires remoteevent to open gui

-player confirms purchase

-localscript fires remote event back to server script

-server script processes payment..

-for some reason after this happens both local and server scripts are continue running.

-player buys shop item again

-it processes the payment twice
10 coins x2 (20 coins)

-if the player buys the item again
it runs the remote event 3 times
10 coins x3 (30 coins)

the price of the item is only 10 coins
why does it keep incrementing the price?

how do i make sure that the script fully disconnects the remote event every time its used i tried setting it to Once but then you can no longer run the remote event at all afterwards.

this is basically whats happening but it all started after i moved the script from inside the object to the serverscriptservice and i dont know why that would affect it

#

the code is a bit more complex than this but it is an example of whats happening i will provide the code im using once someone asks for it but im also using profilestore - datastore and its not a shop item - its a arcade game that is being paid for i just used a shop item to simplify my problem

#

the main issue is i believe once the remote event runs - it doesnt close the connection at the end making it run twice the next time its fired

grave python
#

probably connecting events more than once

vivid wagon
#

my scripts are running a lot of events but ive made sure to seperate them

#

The server script inside serverscript service

local Datamanager = require(game.ServerScriptService.DataStore.Data.DataManager)
local clawStartButton = game.Workspace.Builds.ArcadeBuilding.ClawMachine.ClawMachine1.ClawMachineModel.StartButton
local ClickDetector = clawStartButton:WaitForChild("ClickDetector")
local inUse = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.inUse
local fireclientgui = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.FireClientGui
local firepurchasegui = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.FirePurchaseGui

local Price = 10
ClickDetector.MouseClick:Connect(function(player)
    if inUse.Value then
        player.PlayerGui.ClawMachine.ClawInUse.Visible = true
        task.wait(5)
        player.PlayerGui.ClawMachine.ClawInUse.Visible = false
        
    else
        firepurchasegui:FireClient(player)
    end
end)

firepurchasegui.OnServerEvent:Connect(function(player)
    if player.leaderstats.Coins.Value < Price then
        player.PlayerGui.ClawMachine.PurchaseFail.Visible = true
        task.wait(2)
        player.PlayerGui.ClawMachine.PurchaseFail.Visible = false

    else
        Datamanager.remCoins(player, Price)
        print(Price)
        player.PlayerGui.ClawMachine.PurchaseSuccess.Visible = true
        task.wait(2)
        player.PlayerGui.ClawMachine.PurchaseSuccess.Visible = false
        fireclientgui:FireClient(player)
        inUse.Value = true
    end
end)
tribal heraldBOT
#

studio** You are now Level 2! **studio

vivid wagon
#

hold on ill get the localscript

#

The only part that matters is the VERY bottom where it sends the remoteevent back


local clawMachine = script.Parent
local ClawMachineEventUp = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.ClawMachineEventUp
local ClawMachineEventDown = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.ClawMachineEventDown
local ClawMachineEventLeft = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.ClawMachineEventLeft
local ClawMachineEventRight = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.ClawMachineEventRight
local ClawMachineEventDrop = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.ClawMachineEventDrop
local fireclientgui = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.FireClientGui
local firepurchasegui = game.ReplicatedStorage.Events.GameEvents.ClawMachine1.FirePurchaseGui
local purchase = clawMachine["Purchase?"]
local play = purchase.Play
local quit = purchase.Quit
local clawControls = clawMachine.clawControls
local drop = clawMachine.clawControls.drop
local up = clawMachine.clawControls.up
local down = clawMachine.clawControls.down
local left = clawMachine.clawControls.left
local right = clawMachine.clawControls.right

fireclientgui.OnClientEvent:Connect(function(player)
    clawControls.Visible = true
    local buttonpressed = false
-- EXTRA CODE HERE FOR THE CLAWMACHINE

-- 
end)

firepurchasegui.OnClientEvent:Connect(function(player)
    purchase.Visible = true
    play.MouseButton1Click:Connect(function()
        firepurchasegui:FireServer()
        purchase.Visible = false
    end)
    quit.MouseButton1Click:Connect(function()
        purchase.Visible = false
    end)
end)
grave python
# grave python probably connecting events more than once

deactivates mind-reading powers so like I said...

firepurchasegui.OnClientEvent:Connect(function(player)
    purchase.Visible = true
    play.MouseButton1Click:Connect(function()
        firepurchasegui:FireServer()
        purchase.Visible = false
    end)```
connecting events more than once.
vivid wagon
#

sorry dude im an idiot ive very beginner when it comes to coding - how do i fix this

#

do i seperate the functions

grave python
# vivid wagon do i seperate the functions

the same thing happens to the quit button, but since that doesn't do anything other than setting visible=false, it doesn't matter setting visible=false for each time you fired the firepurchasegui event

vivid wagon
#

hold on

grave python
vivid wagon
#

damn man how long does it take to figure this out i been trying to figure this out since yesterday

#

10x dev

grave python
#

if you want to manually control your event connections, all roblox events return one of these https://create.roblox.com/docs/en-us/reference/engine/datatypes/RBXScriptConnection which you can use to :Disconnect(). do pay attention if you do local foo=bar:connect() foo:Disconnect() if foo then print("still bar") end this is a newb trap because the scriptconnection is not nil and thuse evaluates to true, even though it's disconnected making you think it "should" be false but it isn't.

A connection between an Datatype.RBXScriptSignal and a function.

vivid wagon
#

basically memory leaks

grave python
#

there's a trick for this you can just do foo=foo:Disconnect() hehe

grave python
vivid wagon
#

i started 3 months ago

grave python
vivid wagon
#

ive been trying to figure out why my code was incrementing since yesterday

grave python
#

wha you only been stuck for a day? lucky.

vivid wagon
#

ive only been coding for 3 months im sure ill catch up

#

assuming youve been doing this stuff for years

grave python
#

ja

vivid wagon
#

also what does foo mean XD

grave python
# vivid wagon also what does foo mean XD

The terms foobar (), foo, bar, baz, qux, quux, and others are used as metasyntactic variables and placeholder names in computer programming or computer-related documentation. They have been used to name entities such as variables, functions, and commands whose exact identity is unimportant and serve only to demonstrate a concept.
The style guide...

bold current
#

foo bar 😀

vivid wagon
#

cheers man ill have to look over this sorry i kept disappearing cuz im making dinner

#

i live AUS so its night here

vivid wagon
#
local connection 
    connection = firepurchasegui.OnClientEvent:Connect(function(player)
    purchase.Visible = true
    play.MouseButton1Click:Connect(function()
        firepurchasegui:FireServer()
        purchase.Visible = false
        connection:Disconnect()
    end)
    quit.MouseButton1Click:Connect(function()
        purchase.Visible = false
        connection:Disconnect()
    end)
end)

ima test this not sure if this is right - ill also disconnect the connection on the serverscript side aswell

#

it basically functions the same as :Once where it runs once then wont run again