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

Tycoon furnace touch event increases money multiple times. How to fix?

Asked by 4 years ago
Edited 4 years ago

Having an issue when I tried to make a baseplate as a furnace and when the blocks touched it and points were added sometimes it would give me 2 points or 4 or 5 instead of just 1, adding debounce does not work cuz I don't want to add a wait to it. SpawnBlock is just a function that spawns a block when a player clicks a part in the world. TextChange is the main

IncreaseMoney:

local Player = game.Players.LocalPlayer
local TextLabel = script.Parent
local RS = game:GetService("ReplicatedStorage")
local TextChange = RS:WaitForChild("TextChange")
local Debounce = false

TextChange.OnClientEvent:Connect(function(Part)

    Part:Destroy()
    Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1

end)

Detect ore spawn button being clicked:

local Player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local TextChange = RS:WaitForChild("TextChange")
local SpawnBlock = RS:WaitForChild("SpawnBlock")
local ClickDetector = game.Workspace.Button.ClickDetector

ClickDetector.MouseClick:Connect(function()

    SpawnBlock:FireServer()

end)

Spawn block:

local RS = game:GetService("ReplicatedStorage")
local TextChange = RS:WaitForChild("TextChange")
local SpawnBlock = RS:WaitForChild("SpawnBlock")

SpawnBlock.OnServerEvent:Connect(function(Player)

    local NewPart = Instance.new("Part",game.Workspace)
    NewPart.Position = Vector3.new(0,50,0)
    NewPart.Size = Vector3.new(2,2,2)
    NewPart.BrickColor = BrickColor.new("Really blue")
    NewPart.Material = "Neon"

end)

If ore touched furnace:

local Furnace = game.Workspace.Furnace
local RS = game:GetService("ReplicatedStorage")
local TextChange = RS:WaitForChild("TextChange")

Furnace.Touched:Connect(function(Hit)

    if not Hit.Parent:FindFirstChild("Humanoid") then

        local Part = Hit
        TextChange:FireAllClients(Part)

    end

end)
0
http://idownvotedbecau.se/unclearquestion and there is too little code here, like what is SpawnBlock? programmerHere 371 — 4y
0
Are you increasing your money on the client? Seems like bad design, exploiters can just change the money value. :/ CeramicTile 847 — 4y
0
As if it was worth it LOL. It won't even replicate. It's not even bad because of that it's bad because it won't even replicate ^ programmerHere 371 — 4y
0
Please be a bit more descriptive of what you want, explain it step by step please. Just2Terrify 566 — 4y
0
This is not my main project that's why it's both on client and server so I can change the values through command console. GalTheGod 22 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

In terms of technicality...

Your main issue is that your Part is on the Server, and you are deleting it from the Client. When you create the Part that will touch your Furnace, you do so on the server. This means that every client (and the server) will have this part on their screen.

When the .Touched event gets fired from the Part touching the Furnace you in turn send a signal to all clients telling them to increase their money. You then delete the Part on each client, BUT NOT THE SERVER. This means that the same part that fired the .Touched event could potentially keep firing it depending on how Roblox's physics are feeling in that moment.

To fix the above issue you would have your part be deleted right after doing FireAllClients. This would also eliminate the need for a Debounce on the client, but in case you still wanted one...

You have your Debounce set to false in the TextChanged script, however you never check it, and you don't set it to true or have any sort of cool down. If you were to add a Debounce it would look like this...

local debounce = false

function Cooldown()
    wait(0.1)
    debounce = false
end

function Foo()
    if not debounce then
        debounce = true-- Set this to true so that it doesn't keep firing
        spawn(function()-- Spawn a new thread so that your code doesn't yield
            Cooldown()-- Set a timer for the debounce to refresh
        end
        -- Do your things here
    end
end

THAT BEING SAID, here are some issues I have with your methodology.

You do NOT want to keep track of player money on the client. It is easily exploitable, especially in an IntValue or NumberValue. You would want to store the actual values of the money on the server, perhaps in the ServerStorage. If you need to display a UI piece to the clients, have it read the value from the ServerStorage and send that value to the client.

0
How do I create a leaderboard if it's not on the client? GalTheGod 22 — 4y
0
Like I said in the last paragraph, keep your real values inside of a folder in the ServerStorage, and then use RemoteEvents to send those values to display on your client sided leaderboard. climethestair 1663 — 4y
Ad

Answer this question