-
What do you want to achieve? Players to teleport to a brick without issues using their CFrame.
-
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.
-
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.