of     1   

killette2
#139326533Saturday, July 05, 2014 5:09 PM GMT

I have made a simple .Touched script but I do not know how to get it to repeat itself as long as you are touching the brick it is in. What would I do to go about that? -------------------------- function onTouched(hit) check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local energy = stats:findFirstChild("Energy") energy.Value = energy.Value + 1 wait(3) end end end script.Parent.Touched:connect(onTouched)
killette2
#139328959Saturday, July 05, 2014 5:34 PM GMT

Should I use a while true function? I'm a bit lost
nobbers12345
#139329303Saturday, July 05, 2014 5:37 PM GMT

Use a debounce http://wiki.roblox.com/index.php?title=Debounce I hate the LGBT. Those laser guided battle tanks are just too damn powerful.
KAAK82
#139329988Saturday, July 05, 2014 5:44 PM GMT

local Debounce = false function Test() if not Debounce then Debounce = true --Code Debounce = false end
Frostglacier
#139330892Saturday, July 05, 2014 5:54 PM GMT

I think he wants a code that repeats as long as a player is touching the part, not a debounce script. TouchEnd = true script.Parent.Touched:connect(function (hit) check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then TouchEnd = false while TouchEnd == false do local energy = stats:findFirstChild("Energy") energy.Value = energy.Value + 1 wait(3) end end end end) game.Workspace.Part.TouchEnded:connect(function() TouchEnd = true end) Tested this using health increase; seems to work.
DataStore
#139330931Saturday, July 05, 2014 5:54 PM GMT

@Nobbers, KAAK, Did either of you actually read what Killette2 posted? Or did you just go by the title? He wasn't asking how to do a debounce, but rather to get something to repeat continuously until an object stopped touching another. @OP, Yes, you could use a loop. To get when something stops touching an object you can use the TouchEnded event.
killette2
#139332769Saturday, July 05, 2014 6:13 PM GMT

Thank you frost, I was wondering about the touchend feature. Unfortunately this doesn't seem to be stopping when I stop touching said brick and it also gives me the stat a lot more rapidly than once every 3 seconds, would I need a debounce for this?
nobbers12345
#139333017Saturday, July 05, 2014 6:16 PM GMT

Yes, you would then need debounce, because the action fires every single time it notices you are in contact. I hate the LGBT. Those laser guided battle tanks are just too damn powerful.
killette2
#139333034Saturday, July 05, 2014 6:16 PM GMT

So I messed around more with what I was given and it seems to do it once every 3 seconds, but this happens for every time it is touched ever with any body part. If it is touched 1 time with an arm, it works correctly, but if left and touched again it works incorrectly, as it then gives 2 per 3 seconds. If you jump and rub all over it, the number then ticks up rapidly never stopping.
Frostglacier
#139334249Saturday, July 05, 2014 6:29 PM GMT

I suppose you could add in another BoolValue upon touching the brick which is tested for once another part such as an arm touches the brick. For example, script.Parent.Touched:connect(function (part) value = part.Parent:findFirstChild("BOOLVALUEHERE") if value ~= true then bool = Instance.new("BoolValue") bool.Parent = part.Parent --Codeycodey end end) script.Parent.TouchEnd:connect(function (part) part.Parent.BOOLVALUEHERE:Destroy() end) This isn't a script for your situation exactly, but an idea of what you can do yourself.

    of     1