Here is the script that teleports to one location on touch, but I need it so when you touched the brick/model 3 times, at the fourth time it needs to teleport to a diffrent location. Can someone do that?
place = CFrame.new(97.689, 3.104, 16.411) script.Parent.Touched:connect(function(p) local humanoid = p.Parent:findFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Torso.CFrame = place end end)
Hey flogau62,
local part = script.Parent; -- The part which will be touched to activate teleportation. local active_location; -- The variable for the current location local num_touch = 0; -- The variable that keeps track of the amount of touches. local loc = 1; -- The variable that keeps track of the index of the location in the table. local deb = false; -- The variable for debounce. local locations = {CFrame.new(97.689, 3.104, 16.411), CFrame.new(1, 1, 1), CFrame.new(9, 9, 9)} -- Table to store all locations you need. part.Touched:Connect(function(obj) -- Anonymous function connected to the Touched event local hum = obj.Parent:FindFirstChild("Humanoid"); -- Variable for humanoid if there is one. if hum and not deb then -- Checks if there is a humanoid and if deb is false. deb = true; -- Sets deb to true for debounce purposes num_touch = num_touch + 1; -- Increases the number of touches by 1. if num_touch == 4 then -- Checks if the amount of touches are 4 num_touch = 0; -- Sets the amount of touches back to 0. if loc == #locations then -- Checks if loc is as great as can be and if it can then it sets loc back to 1. Therefore, once you have ran out of all the CFrames, in the table it goes back to the first one so the code doesn't error saying there isn't the next CFrame. loc = 1; -- Sets loc to 1. else -- If loc isn't equal to the amount of locations in the table. loc = loc + 1; -- Increases loc by 1 since 4 touches have been completed. end -- end for loc if statement end -- end for num_touch if statement active_location = locations[loc]; -- Updates the location to the new/old one. local char = obj.Parent; -- Variable for the Character local torso = char:WaitForChild("HumanoidRootPart"); -- Variable for the torso torso.CFrame = active_location; -- Sets the torso's location to the one in the table. wait(1) -- Cool down for 1 second so this function doesn't run twice with 1 touch. deb = false; -- Sets debounce to false. end -- end for the if hum and not deb if statement. end) -- en.d for the anonymous function.
~~ KingLoneCat