Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why when i touching the block it gives me 20-30 leaderstats value when i need 1?

I made script what counts on what stage you are. So i scripted when you touching portal leaderstats value needs to be 1, it gives me around 25 stages?

Leaderstats script :


local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local money = Instance.new("IntValue")
money.Name = "Stages"
money.Value = 0
money.Parent = leaderstats

end

game.Players.PlayerAdded:Connect(onPlayerJoin)

local touchName = "Stages" local rs = game:GetService("ReplicatedStorage")

local touchEvent = rs:WaitForChild('TouchEvent')

touchEvent.OnServerEvent:Connect(function(plr)

plr.leaderstats[touchName].Value = plr.leaderstats[touchName].Value +1

wait(1)

end)


StarterPack script:

local touchName = "Stages"
local rs = game:GetService("ReplicatedStorage")

local touchEvent = rs:WaitForChild('TouchEvent')
local portal = workspace.FirstStage.FrostPartal.PortalPart

portal.Touched:Connect(function()
	touchEvent:FireServer()
end)

1 answer

✓ Accepted answer

The problem is you have no touch "Debounce" in your portal. So it looks like it's firing each time a part of the player like arms, legs, accessories etc... touch the portal part.

To fix that, change this:

StarterPack script:

local touchName = "Stages" local rs = game:GetService("ReplicatedStorage")

local touchEvent = rs:WaitForChild('TouchEvent') local portal = workspace.FirstStage.FrostPartal.PortalPart

portal.Touched:Connect(function() touchEvent:FireServer() end)


To this:

StarterPack script:

local touchName = "Stages"
local rs = game:GetService("ReplicatedStorage")

local touchEvent = rs:WaitForChild('TouchEvent')
local portal = workspace.FirstStage.FrostPartal.PortalPart

--// debounce code! Variable declare
local Debounce = false

portal.Touched:Connect(function()
	if(Debounce == false) then --// check for our debounce is false or accepting 
		Debounce = true --// set it to true for this part
		touchEvent:FireServer() --// call the server script
		wait(1) --// wait 1 second to stop repeated touches, change this to your liking but not too small otherwise it will bug out again!.
		Debounce = false --// free up our debounce variable for next run
	end
end)

Hope this helps! :)

1 comment

0

Thanks so much! I have one question, how to make script work once for one player? Because i have button "Back To Start"

This discussion is preserved as it was. New answers, comments, and votes are closed.