Strange bug with certain gears and teleport script

  1. What do you want to achieve? Players to teleport to a brick without issues using their CFrame.

  2. What is the issue? When using certain gears, the game would act like the player stepped on the teleporting pad again and activates the teleporting function.

  3. What solutions have you tried so far? Can’t find anyone else with this issue, I suspect it has something to do with the functions in the gear’s scripts that creates a variable with the user’s CFrame, as only during gear activation does this occur.

Essentially, I’m trying to figure out how Lua works so I’m trying to make a simple tycoon game, in this game there’s a teleporting pad that teleports a player to the top of the tycoon, all is well until a player decided to use a gear, for whatever reason when activating certain gears the game behaves like the player has stepped on the pad again and teleports them. I have no clue what causes this as the function should only activate on touch. There’s a chance I’m completely missing something obvious here but I can not figure out why.

Code here for the teleport pad (it’s essentially the same as any free model version)

local TeleportPart1 = script.Parent.TeleportPart1
local TeleportPart2 = script.Parent.TeleportPart2
local TpBrick1 = script.Parent.TpBrick1
local TpBrick2 = script.Parent.TpBrick2
local tpSound = script.Parent.Part.Teleport
debounce = false

TeleportPart1.Touched:Connect(function(hit)
	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w and debounce == false then
		print("player hit")
		debounce = true
		TeleportPart2.CanTouch = false
		w.CFrame = TpBrick2.CFrame
		tpSound:Play()
		wait(2)
		TeleportPart2.CanTouch = true
		debounce = false
	end
end)

TeleportPart2.Touched:Connect(function(hit)
	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w and debounce == false then
		local char = w.Parent
		print("player hit")
		debounce = true
		TeleportPart1.CanTouch = false
		w.CFrame = TpBrick1.CFrame
		tpSound:Play()
		wait(2)
		TeleportPart1.CanTouch = true
		debounce = false
	end
end)

Example code for a gear that activates this issue. This is the Orinthian Axe and the bug occurs when using the special ability (Video will makes thing clear)

function ThrowAxe.OnServerInvoke(Player,Key)
	if not Tool.Enabled or not Player or Player ~= MyPlayer or not Key or AxeThrown then return end
	if Key == Enum.KeyCode.Q then
		if MyHumanoid and MyHumanoid.Health > 0 then
			local playerPos = MyHumanoid.Parent.HumanoidRootPart.Position
			print(playerPos)
			AxeThrown = true
			Animations.Throw:Play();Animations.Throw.Stopped:Wait()
			if Tool.Parent ~= MyCharacter then AxeThrown = false return end
			local TargetPoint = MouseLoc:InvokeClient(Player)
					
			local ProjectileScriptClone = ProjectileScript:Clone()
			if TargetPoint == 0 then
				ProjectileScriptClone.TargetPos.Value = playerPos + Vector3.new(15, 0, 0)
			else
				ProjectileScriptClone.TargetPos.Value = TargetPoint
			end
			ProjectileScriptClone.Disabled = false
			ProjectileScriptClone.Parent = Tool
			Handle.Transparency = 1
			Properties.CurrentDamage = 0
			repeat
				Services.RunService.Heartbeat:Wait()
			until not ProjectileScriptClone or not ProjectileScriptClone.Parent
			Handle.Transparency = 0
			AxeThrown = false
		end
	end
end

It isn’t only for the Orinthian axe either, there are other gears that cause this issue as well (for example dynamite)
What I do know about the issue

  • Occurs when using certain gear special abilities
  • Occurs when using gears that drops in front of player (bombs, dynamite etc)
  • Fixes itself temporarily when stepping on the teleporter again, keyword temporarily, as it starts happening again randomly anytime the player steps on the teleporter again
  • Might have something to do with how the gear is grabbing player’s positions in the functions

Other than that I have nothing, I’m a complete newbie when it comes to scripting on Roblox so there’s a good chance I might have overlooked something.

that is a strange bug, but i would suggest making a copy of the tool, and just get rid of all the code and see if it still has an issue

The issue only occurs when the throwaxe function is activated, so of course removing it would just prevent the issue from happening in the first place haha. I understand majority of the gears in the catalog are defunct and use deprecated code, so the issue could just be way out of my area of expertise.

hmm?
maybe try to remove code until it stops causing the issue?

Is there anything coming out in the output window? Also add a print(hit.Name) to the beginning of your teleportpart functions…maybe the tool is hitting the pad instead of a player?

No errors in the output window but when I added print(hit.name) interestingly enough it’s behaving as the HumanoidRootPart touched the teleporter brick whenever I activate the ability. Could by chance whenever the function stores the position of the HumanoidRootPart in the playerPos variable it occurs? How could this even happen?

If I remove the variable the ability would not work as it will have no other access to the player’s current position to my current knowledge.

Can you try it by making the ProjectileScriptClone.Parent = workspace instead of the Tool and see if that might work. Just a thought.

Sadly didn’t work, created an infinite yield error.

maybe try commenting all the lines inside the tool, and then uncommit lines until it breaks

Ah okay maybe other code is looking for it inside the Tool. I just figured that if the axe is thrown and it is inside the tool its bounding box would expand if the axe is thrown.

I’ll be trying your suggestion, the only problem is commenting out the first couple variables breaks the entire tool haha, I’ll see what I can remove if possible to see if I could keep the problem from occurring, but I doubt as the issue only occurs when the throwaxe function is activated.

local Seed --Randomness

local Tool = script.Parent

local Grips = {Normal = CFrame.new(0, -0.899999976, 0.25, 1, 0, 0, 0, 1, 0, 0, 0, 1)}

Tool.Grip = Grips.Normal

Tool.Enabled = true --Ensure the tool wouldn't break easy

local Handle = Tool:WaitForChild("Handle",10)
Handle.Transparency = 0

local ThrowAxe = Tool:WaitForChild("ThrowAxe",10)

local MouseLoc = Tool:WaitForChild("MouseLoc",10)

local MyPlayer,MyCharacter,MyHumanoid,MyTorso


local Services = {
	Debris = (game:FindService("Debris") or game:GetService("Debris")),
	RunService = (game:FindService("RunService") or game:GetService("RunService")),
	Players = (game:FindService("Players") or game:GetService("Players")),
}

local Sounds = {
	Unsheath = Handle:WaitForChild("UnsheathSound"),
	Slash = Handle:WaitForChild("SlashSound"),
}

local Properties = {
	BaseDamage = 5,
	SlashDamage = 10,
	SwingDamage = 15,
	CurrentDamage = 0,
}

local ProjectileScript = script:WaitForChild("ProjectileScript",10)

local Directory,Animations

local TouchConnection

local AxeThrown = false

function IsTeamMate(Player1, Player2)
	return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end

function UntagHumanoid(humanoid)
	for _, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

function TagHumanoid(humanoid, player)
	local CreatorTag = Instance.new("ObjectValue")
	CreatorTag.Name = "creator"
	CreatorTag.Value = player
	CreatorTag.Parent = humanoid
	Services.Debris:AddItem(CreatorTag, 3)
end

function Blow(Hit)
	if not Hit or not Hit.Parent then return end
	
	local Hum = Hit.Parent:FindFirstChildOfClass("Humanoid")
	
	if Hum and Hum ~= MyHumanoid and Hum.Health > 0 and not AxeThrown then  
		if IsTeamMate(MyPlayer,Services.Players:GetPlayerFromCharacter(Hum.Parent)) then return end
		UntagHumanoid(Hum)
		TagHumanoid(Hum,MyPlayer)
		Hum:TakeDamage(Properties.CurrentDamage)
	end
end

function SpinSword(SpinTime)
	spawn(function()
		local StartSpin = tick()
		local EndSpin = StartSpin + SpinTime
		while tick() < EndSpin do
			Tool.Grip = Grips.Normal * CFrame.Angles(math.pi * 2 * ((tick() - StartSpin) / SpinTime), 0, 0)
			wait()
		end
		Tool.Grip = Grips.Normal
	end)
end

function Equipped()
	Properties.CurrentDamage = Properties.BaseDamage
	Seed = Random.new(tick())
	MyCharacter = Tool.Parent
	MyPlayer = Services.Players:GetPlayerFromCharacter(MyCharacter)
	MyHumanoid = MyCharacter:FindFirstChildOfClass("Humanoid")
	MyTorso = MyCharacter:FindFirstChild("HumanoidRootPart") or MyCharacter:FindFirstChild("Torso")
	if not MyHumanoid or MyHumanoid.Health <=0 then return end
	
	Directory = Tool:WaitForChild(MyHumanoid.RigType.Name)
	
	Animations = {
		LeftSlash = Directory:WaitForChild("LeftSlash"),
		LeftSwingFast = Directory:WaitForChild("LeftSwingFast"),
		OverHeadSwing = Directory:WaitForChild("OverHeadSwing"),
		RightSlash = Directory:WaitForChild("RightSlash"),
		RightSwingFast = Directory:WaitForChild("RightSwingFast"),
		Throw = Directory:WaitForChild("Throw")
	}
	for AnimName,Anim in pairs(Animations) do
		Animations[AnimName] = MyHumanoid:LoadAnimation(Anim)
	end
	
	Sounds.Unsheath:Play()
	
	TouchConnection = Handle.Touched:Connect(Blow)
end

function Unequipped()
	Properties.CurrentDamage = 0
	
	for AnimName,Anim in pairs(Animations) do
		Anim:Stop()
	end
	if TouchConnection then TouchConnection:Disconnect() end
end

function Activated()
	if not MyHumanoid or MyHumanoid.Health <=0 or not Tool.Enabled or AxeThrown then return end
	
	Tool.Enabled = false
	local AnimBank = {Animations.LeftSlash,Animations.OverHeadSwing,Animations.RightSlash,Animations.RightSwingFast,Animations.LeftSwingFast}
	
	local ChosenAnim = AnimBank[Seed:NextInteger(1,#AnimBank)]
	ChosenAnim:Play()
	
	if ChosenAnim.Animation.Name == "RightSlash" or ChosenAnim.Animation.Name == "LeftSlash" or ChosenAnim.Animation.Name == "OverHeadSwing" then
		SpinSword(.5)
	end
	
	if ChosenAnim.Animation.Name == "OverHeadSwing" then
		Properties.CurrentDamage = Properties.SwingDamage
	else
		Properties.CurrentDamage = Properties.SlashDamage
	end
	print(ChosenAnim.Animation.Name)
	Sounds.Slash:Play()
	
	wait(0.7)
	Properties.CurrentDamage = Properties.BaseDamage
	Tool.Enabled = true
end

Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Tool.Activated:Connect(Activated)

function ThrowAxe.OnServerInvoke(Player,Key)
	if not Tool.Enabled or not Player or Player ~= MyPlayer or not Key or AxeThrown then return end
	if Key == Enum.KeyCode.Q then
		if MyHumanoid and MyHumanoid.Health > 0 then
			local playerPos = MyHumanoid.Parent.HumanoidRootPart.Position
			print(playerPos)
			AxeThrown = true
			Animations.Throw:Play();Animations.Throw.Stopped:Wait()
			if Tool.Parent ~= MyCharacter then AxeThrown = false return end
			local TargetPoint = MouseLoc:InvokeClient(Player)
					
			local ProjectileScriptClone = ProjectileScript:Clone()
			if TargetPoint == 0 then
				ProjectileScriptClone.TargetPos.Value = playerPos + Vector3.new(15, 0, 0)
			else
				ProjectileScriptClone.TargetPos.Value = TargetPoint
			end
			ProjectileScriptClone.Disabled = false
			ProjectileScriptClone.Parent = Tool
			Handle.Transparency = 1
			Properties.CurrentDamage = 0
			repeat
				Services.RunService.Heartbeat:Wait()
			until not ProjectileScriptClone or not ProjectileScriptClone.Parent
			Handle.Transparency = 0
			AxeThrown = false
		end
	end
end

Here’s the entire server code for the axe.

im not quite sure, none of that should break it?

I’m throwing this in the dark, but perhaps this repeat loop might be preventing your axe from completing its function

			ProjectileScriptClone.Disabled = false
			ProjectileScriptClone.Parent = Tool
			Handle.Transparency = 1
			Properties.CurrentDamage = 0
			repeat
				Services.RunService.Heartbeat:Wait()
			until not ProjectileScriptClone or not ProjectileScriptClone.Parent

If that’s working as intended, you can check in the workspace if the axe is parented to the character.

You could also see if your teleportation method might be improvable:
w.CFrame = TpBrick1.CFrame could be hit.Parent:PivotTo(TpBrick1.CFrame)

Again, troubleshooting is trial and error, and since I can’t replicate the environment in your game, the only thing that we can do is give you troubleshooting methods.

Is this Axe from the toolbox? If so what is the keyword to search and who created it?

The Orinthian axe is a Roblox gear. As I said earlier most gears in the Roblox catalog are defunct and used deprecated code but this one works as intended except for the issue that’s occurring in my game which is so strange.

It seems as changing the teleportation method worked, thanks! It makes this all seem a little too silly now. I’ll do a couple more tests but for now it seems as though there is no issue with the player getting teleported now.

Update: The issue starting reoccurring again, whoops. Strangely enough if the tool is in the player’s starterpack the issue only occurs during specific circumstances (ex: the axe is thrown and player steps on teleporting pad before the axe is returned) yet when the player is given the tool the issue immediately occurs when the axe is thrown after using the teleporter for the first time.

could you make a place file where its just the teleporter and the tool, so that we could test it?

OrinthianAxeTeleporter.rbxl (55.7 KB)
Made one, strangely enough the issue doesn’t replicate the same as it does in my other place, it still occurs but unlike how it occurs when the player is given the gear through the giver, the issue only arises when using the throw ability then stepping on the teleporter.