✓ Accepted answer
Hey flogau62,
For what you're trying to accomplish you just need to do some basic arithmetic and logical programming also, I recommend using tables like I did with mine. Also, make it so your code works under any circumstances like I made mine which I will show you below in a while.
###So, what I did in my code is I had a variable for the location, I made a table of all the locations and every time they made a 4th touch, I changed the location to the next one in the table. That's basically what I did. Also, I added 1 to the variable that kept a record of the amount of touches and once those touches reached 4, it would update the location. Below is my code and please, don't just out-right copy my code but, I want you to learn from it. The only one it will demerit if you copy the code and not even try to understand it is you in the long run because, this code is very basic and I wouldn't even care if somebody was to copy it but, if I were you I'd care about myself just copying code and not going the extra mile to have an understanding of it. It will help you in the long run so, thanks for complying. Below is the code and I will explain the code line by line.
local part = script.Parent;
local active_location;
local num_touch = 0;
local loc = 1;
local deb = false;
local locations = {CFrame.new(97.689, 3.104, 16.411), CFrame.new(1, 1, 1), CFrame.new(9, 9, 9)}
part.Touched:Connect(function(obj)
local hum = obj.Parent:FindFirstChild("Humanoid");
if hum and not deb then
deb = true;
num_touch = num_touch + 1;
if num_touch == 4 then
num_touch = 0;
if loc == #locations then
loc = 1;
else
loc = loc + 1;
end
end
active_location = locations[loc];
local char = obj.Parent;
local torso = char:WaitForChild("HumanoidRootPart");
torso.CFrame = active_location;
wait(1)
deb = false;
end
end)
##Well, I hope I helped and I hope you have a nice day/night.
~~ KingLoneCat
3 comments
Thanks A lot man! :D
You spent too much time on this.
No problem @flogau62. And, I know @cabbler but if I'm gonna help a person I'd like to help them to the best of my ability.