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)
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
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.