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

How to make cash giver button keep giving cash until the player stops touching?

Asked by 4 years ago

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)
0
Instead of using a touched event, use region3 to check if a player is in a certain space in the workspace. It's much more reliable for what you're doing. AbusedCocopuff4 105 — 4y
0
hi, someone moderated your question about the coins. to answer your question, you should be using a local script instead of a normal scripts. this will make the coin be visible/invisible locally. royaltoe 5144 — 4y
0
a local script wouldn't work with the npc which is the idea behind the question as the npc is server side not client WaterlooBuilder 4 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
You missed an end, in the last part Spjureeedd 385 — 4y
0
Syntax error on line 18 DeceptiveCaster 3761 — 4y
0
no error after fixing the end and == issue but the value is not increasing WaterlooBuilder 4 — 4y
Ad

Answer this question