Reapeat Until not working?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to achive when a player stands on a button the script keeps giving points to the player until the player walks off

  1. What is the issue?

The script only gives cash when the player walks on the part and not just stand

  1. What solutions have you tried so far?

I couldn’t find anything that helps

CODE:

local repStorage = game:GetService("ReplicatedStorage")
local Events = repStorage:FindFirstChild("Events")
local AddCash = Events:FindFirstChild("AddCash")

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
		repeat
		player.Stats.Cash.Value += 1 * player.Stats.Rebirths.Value
	    until script.Parent.TouchEnded
	end
end)

Anything would help. Thank you!

I would recommend using a while true loop on the touched event and a return statement on a touch ended event.

Connections dont work like that, try Event:Wait() instead.

TouchEnded is an event, not a bool property. Try this instead:

script.Parent.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(character)

	if not (character and humanoid and player) then return end

	local touchHasEnded = false
	script.Parent.TouchEnded:Once(function() touchHasEnded = true end)

	wait(1)
	repeat
		player.Stats.Cash.Value += 1 * player.Stats.Rebirths.Value
		wait(1)
	until touchHasEnded
end)

This worked. Thank you very much everyone!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.