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

why is the script causing spam even with a Debounce on it?

Asked by
lytew 99
4 years ago
Edited 4 years ago

hello. So, I created a script that adds "+1" to the money of the player who touched a coin. apparently, the script is right, but some coins that the player touches (I don’t know if it’s a glitch or something I forgot to put in the script), instead of adding "+1" to your money, a much larger number is added (+3 or +4 ...) script:

01local player = game.Players.LocalPlayer
02player.CharacterAdded:Wait()
03db = false
04local cointouchevent = game:GetService("ReplicatedStorage"):WaitForChild("Slotdata"):WaitForChild("CoinDestroy")
05local hum = player.Character:WaitForChild("Humanoid")
06pointsvalue = player:WaitForChild("leaderstats"):WaitForChild("Points")
07 
08    local sound = Instance.new("Sound",player.PlayerGui)
09    sound.SoundId = 'rbxassetid://203620899'
10    sound.MaxDistance = 100
11    sound.Volume = 4
12 
13 
14hum.Touched:Connect(function(hit)
15            if hit.Name == "Coin" then
View all 25 lines...

It is as if there was no Debounce (which I put to avoid spam.

1 answer

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

Hello. Try using a table. Try this:

01local player = game.Players.LocalPlayer
02player.CharacterAdded:Wait()
03db = false
04local cointouchevent = game:GetService("ReplicatedStorage"):WaitForChild("Slotdata"):WaitForChild("CoinDestroy")
05local hum = player.Character:WaitForChild("Humanoid")
06pointsvalue = player:WaitForChild("leaderstats"):WaitForChild("Points")
07 
08    local sound = Instance.new("Sound",player.PlayerGui)
09    sound.SoundId = 'rbxassetid://203620899'
10    sound.MaxDistance = 100
11    sound.Volume = 4
12 
13local touchedCoins = {}
14 
15hum.Touched:Connect(function(hit)
View all 42 lines...

When a coin is touched, it gets inserted into the table. Then every 5 seconds the coin in the touchedCoins array gets removed. Please accept and upvote this answer if it helped.

0
hello @ youtubermasterWOW. So, I tried, but if the wait is too long, when the player touches more than one currency, the value of your Money (Points) will not increase. lytew 99 — 4y
0
Try making the wait less longer. youtubemasterWOW 2741 — 4y
0
Actually, try now. I've edited it. youtubemasterWOW 2741 — 4y
0
Also, don't add the value on the client as it won't show for the server. Use a RemoteEvent. youtubemasterWOW 2741 — 4y
View all comments (8 more)
0
what's wrong with it not being displayed by the server? lytew 99 — 4y
0
If it's not displayed by the server, when your changing a value or checking if a player has coins, it'll return 0 as of Filtering Enabled. youtubemasterWOW 2741 — 4y
0
could I send this information to the server then? so that the player doesn't have a delay when picking up a coin lytew 99 — 4y
0
You'd also need a RemoteEvent for that. youtubemasterWOW 2741 — 4y
0
so i need to put a remoteevent to inform the server how many Points does the player have? lytew 99 — 4y
0
I guess you could use ":FireServer(player.leaderstats.Points.Value)" BUT that would be easily exploited. youtubemasterWOW 2741 — 4y
0
even with FilteringEnabled active? lytew 99 — 4y
0
Yes. Filtering Enabled is forced enabled now. youtubemasterWOW 2741 — 4y
Ad

Answer this question