Trying to make a cash giving button that fires an event for the duration of time the player/npc is touching the part. so say a button is supposed to give 100 cash a second and a player stands on the button for 10 seconds they are supposed to get 1000 cash but only get 300-500 depending on how many times the player touched the button walking into in. how do i keep a function firing until the player/npc stops touching the part?
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then local npc = hit.Parent local maxWood = npc.Configuration.MaxWood local wood = npc.Configuration.Wood while wood.Value < maxWood.Value do wood.Value = wood.Value +1 wait(2) return end end end)
local touching = false local npc script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then touching = true --Tells the game they are touching it using a boolean npc = hit.Parent end end) script.Parent.TouchedEnded:Connect(function(hit) if hit.Parent:FindFirstChildOfClass("Humanoid") then touching = false--Tells the game they are NOT touching it using a boolean end end) while touching = true do local maxWood = npc.Configuration.MaxWood local wood = npc.Configuration.Wood while wood.Value < maxWood.Value do wood.Value = wood.Value +1 wait(2) return end
Hope this works!