Need help with PTS command

Hello, so I am trying to create a PTS command that allows any player to say “!PTS” then an admin will get a popup says (“Player name” needs assistance!) I have done this but I can’t figure out how someone can teleport to the player that made the PTS request, I will provide the script below:

local Plugin = function(...)
	local Data = {...}

	local remoteEvent = Data[1][1]
	local remoteFunction = Data[1][2]
	local returnPermissions = Data[1][3]
	local Commands = Data[1][4]
	local Prefix = Data[1][5]
	local actionPrefix = Data[1][6]
	local returnPlayers = Data[1][7]
	local cleanData = Data[1][8] 

	local pluginName = 'PTS'
	local pluginPrefix = actionPrefix
	local pluginLevel = 0
	local pluginUsage = ""
	local pluginDescription = "Asks question."

	local function pluginFunction(Args)
		local Player = Args[1]
		for _,v in pairs(game.Players:GetChildren()) do
			if returnPermissions(v) >= 1 then
				if game.ReplicatedStorage.PTSENABLED.Value == true then -- Ensure PTSENABLED is a boolean value
					remoteEvent:FireClient(v,"Notif",Player.Name, Player.Name..' called a PTS!',{'PTS','Username: '..Player.Name,' 	'})
					remoteEvent:FireClient(Player,"Notif","PTS", 'Success',{'PTS','Success',' 	'})
				else
					remoteEvent:FireClient(Player,"Notif","PTS", 'Disabled',{'PTS','Disabled',' 	'})
				end
			end    
		end
	end

	local descToReturn
	if pluginUsage ~= "" then
		descToReturn = pluginPrefix..pluginName..' '..pluginUsage..'\n'..pluginDescription
	else
		descToReturn = pluginPrefix..pluginName..'\n'..pluginDescription
	end

	return pluginName,pluginFunction,pluginLevel,pluginPrefix,{pluginName,pluginUsage,pluginDescription}
end

return Plugin

So, that is what I have gotten so far, as I mentioned before I don’t know how to make it so a Moderator+ can teleport to the player that requested the PTS, I would appreciate any help. Also this is using Basic Admin Essentials.

Hey, there are lots of similar posts like this! To execute this, so someone can teleport take a look at this script.

NOTE: This script utilises the BAE plugin system!


local Plugin = function(...)
    local Data = {...}

    -- Included Functions and Info --
    local remoteEvent = Data[1][1]
    local remoteFunction = Data[1][2]
    local returnPermissions = Data[1][3]
    local Commands = Data[1][4]
    local Prefix = Data[1][5]
    local actionPrefix = Data[1][6]
    local returnPlayers = Data[1][7]
    local cleanData = Data[1][8]

    -- Plugin Configuration --
    local pluginName = 'help'
    local pluginPrefix = actionPrefix
    local pluginLevel = 0
    local pluginUsage = ""
    local pluginDescription = "Call for an admin's support."

    -- Example Plugin Function --
    local function pluginFunction(Args)
        local Player = Args[1]
        for _, Admin in ipairs(game.Players:GetPlayers()) do
            if returnPermissions(Admin) >= 1 then
                -- Send notification to admins
                remoteEvent:FireClient(Admin, "Notif", "Help Requested", "Click to teleport", Player.Name)

                -- Teleport admin to the player requesting help
                Admin.Character:MoveTo(Player.Character.HumanoidRootPart.Position)
            end
        end
    end

    -- Return Everything to the MainModule --
    local descToReturn
    if pluginUsage ~= "" then
        descToReturn = pluginPrefix..pluginName..' '..pluginUsage..'\n'..pluginDescription
    else
        descToReturn = pluginPrefix..pluginName..'\n'..pluginDescription
    end

    return pluginName, pluginFunction, pluginLevel, pluginPrefix, {pluginName, pluginUsage, pluginDescription}
end

return Plugin

If this helped, mark this as solution! I didn’t make this script completely, but edited it from an original script made by @CreatorOfSpaceee. All credits can go to them.

Doesn’t work? Let me know and I can help solve this.

Of course, edit the command name and description to your liking.

I have just tested this again and it dose work.

2 Likes

I’m sorry, I think I may be doing something wrong, I am receiving the notification when I use the command, but I am not teleporting to the player once I click on the notification, btw I appreciate you helping me.

My, bad just tried it in a public game, I want it to teleport me once I click on the pop up. In this script in just automatically teleports me to the person that needs help.

1 Like

Alright. I’m gonna help you troubleshoot this, we’re in this together.

So, basically, the teleportation isn’t functioning as expected when you click on the notification popup, right?

A Few Things to Check!

1. Permission Levels

  • Make sure that the player trying to teleport has the appropriate permissions (Moderator or higher) set up correctly in your system.
  • Without these sufficient permissions, the teleportation won’t work at ALL.

2. Character Position

  • Make sure that both the player needing assistance and the admin trying to teleport have their characters properly positioned.
  • On multiple occasions, issues can arise if the characters are in inaccessible or obstructed areas.

3. Script Execution

  • Please double-check that the script is executing correctly without any errors.
  • You should definitely check the output/console for any error messages that might indicate what’s going wrong, and please send screenshots of it if you do find anything!

4. RemoteEvent Handling

  • Another vital thing; verify that the RemoteEvent handling the teleportation request is set up correctly on both the client and server sides.
  • You NEED to make sure that it’s properly listening for and responding to requests.

5. Testing Environment

  • This has helped me before when I had a similar issue; test the script in a controlled environment (e.g., a private testing server) to eliminate ANY external factors that might be interfering with its functionality.

6. Output-Directed Troubleshooting

  • You should definitely apply output-directed troubleshooting.
  • In simple terms, add print statements after most blocks of code to see what prints and what doesn’t. Whenever something doesn’t print, you know that’s where the code stopped, and that’s most likely your bug IF you have any.

Reviewing Your Script!

After I reviewed the script provided in the reply, it seems generally well-structured for its intended purpose. BUT, I do think there might be a couple of adjustments to consider!

  1. Positioning for Teleportation:
  • The script currently attempts to teleport the admin using Admin.Character:MoveTo(Player.Character.HumanoidRootPart.Position).
  • This line, basically, assumes that BOTH the admin and the player needing assistance have their characters loaded and accessible.
  • You should definitely make sure that both players are indeed present in the game and have their characters properly loaded when the teleportation attempt occurs.
  1. Error Handling:
  • This script lacks error handling, which, in fact, is pretty key! I’ve been a scripter for around 8 years so I’m pretty experienced in this, not to bluff! :sweat_smile:
  • So, you should implement error handling to catch any potential issues that might occur during teleportation.
  • For instance, if either the admin or the player needing assistance is not present in the game or their character isn’t properly loaded, the script should handle such cases GRACEFULLY to prevent errors from crashing the game.

This is a revised script I made that should cover the barebones but you should definitely go over it and make some changes, just a small rough draft to give you an idea!

-- Example Plugin Function --
local function pluginFunction(Args)
    local Player = Args[1]
    for _, Admin in ipairs(game.Players:GetPlayers()) do
        if returnPermissions(Admin) >= 1 then
            -- Send notification to admins
            remoteEvent:FireClient(Admin, "Notif", "Help Requested", "Click to teleport", Player.Name)

            -- Teleport admin to the player requesting help
            if Admin.Character and Admin.Character:FindFirstChild("HumanoidRootPart") and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
                Admin.Character:MoveTo(Player.Character.HumanoidRootPart.Position)
            else
                warn("Teleportation failed: Missing character or humanoid root part for either admin or player.")
            end
        end
    end
end

These adjustments SHOULD enhance the script’s “robustness” and provide more insights into any specific or possible issues that might be occurring during teleportation. After you make these changes and review everything, test the script again and observe its behavior to see if it resolves the teleportation issue, and if not, keep reading because I might’ve made a few mistakes, haha.

You don’t need to rely on my edited version, just follow the things I listed to check out instead and you’ll most likely be good.

If you’ve gone through these steps and the issue persists, let me know, and we can go further into resolving the problem.

Or, even if you absolutely get NO testing feedback from this, then once again reply to this and I’ll do a deeper investigation. If you do get any feedback, then BOOM! You have your problem right there. If you’re unsure what to do with it, or how to fix it using that information, again, reply to this and I’d be glad to help ya out. :grin:

so sorry for the long response :sweat_smile:

Please feel free to mark this as a solution if I helped you! :smiling_face:

1 Like

After using that script it just automatically teleports me to the player, I was hoping to have it so that I teleport to the player once I click on the Notification, do you think there is any way that’s possible? I’ve been trying for near a week now and I’m really struggling, would appreciate any help.

Sure!

The Modification Plan:

We can refine the script to make sure that that the teleportation occurs only when the admin clicks on the notification. This requires a bit of a different approach. SO, we’ll modify the script to handle the teleportation upon receiving a specific event triggered by clicking the notification.

Anyways, you can adjust the script to something like what’s below.

The Modified Code

-- Example Plugin Function --
local function pluginFunction(Args)
    local Player = Args[1]
    for _, Admin in ipairs(game.Players:GetPlayers()) do
        if returnPermissions(Admin) >= 1 then
            -- Send notification to admins
            remoteEvent:FireClient(Admin, "Notif", "Help Requested", "Click to teleport", Player.Name)
        end
    end
end

-- Handle teleportation upon notification click
remoteEvent.OnServerEvent:Connect(function(player, action, targetPlayer)
    if action == "TeleportToPlayer" then
        if returnPermissions(player) >= 1 then
            local targetPlayerObject = game.Players:FindFirstChild(targetPlayer)
            if targetPlayerObject then
                if player.Character and player.Character:FindFirstChild("HumanoidRootPart") and targetPlayerObject.Character and targetPlayerObject.Character:FindFirstChild("HumanoidRootPart") then
                    player.Character:MoveTo(targetPlayerObject.Character.HumanoidRootPart.Position)
                else
                    warn("Teleportation failed: Missing character or humanoid root part for either admin or target player.")
                end
            else
                warn("Teleportation failed: Target player not found.")
            end
        else
            warn("Teleportation failed: Insufficient permissions.")
        end
    end
end)

What I Modified

In this version that I modified for ya, when an admin receives the notification and clicks on it, a server-side event (OnServerEvent) is triggered. Then, the server listens for this event and handles the teleportation logic accordingly.

Breaking It Down

  1. Plugin Function:
  • The pluginFunction is called when a player triggers the command to request assistance (!PTS in this case). It sends a notification to all admins in the game!
  1. Handling Notification Clicks:
  • When an admin receives the notification and clicks on it, a client-side script should be responsible for triggering a server-side event. Let’s call this event as “NotificationClicked”.
  • This event should carry information about the action being performed (in this case, “TeleportToPlayer”) and the target player’s name.
  • The server listens for this event and handles the teleportation logic.
  1. Server-side Teleportation Logic:
  • Upon receiving the “NotificationClicked” event, the server checks if the player triggering the event has sufficient permissions (Moderator or higher).
  • If the player has sufficient permissions, the server looks for the target player by their name.
  • Once the target player is found, the server checks if both the admin and the target player have their characters loaded and accessible.
  • If everything is in order, the server teleports the admin to the target player’s position.

Explanation Expansion & Potential Bugs

  1. Plugin Function Explanation:
  • The pluginFunction iterates over all players in the game to find admins (players with permission level 1 or higher).
  • For each admin found, it sends a notification informing them that assistance is needed, along with the name of the player requesting help.
  1. Handling Notification Clicks:
  • When an admin receives the notification and clicks on it, a client-side script should trigger a server-side event named “NotificationClicked”.
  • This event should contain two crucial pieces of information: the action being performed (in this case, “TeleportToPlayer”) and the name of the player to whom the teleportation should occur.
  • The server is set up to listen for this event and execute the teleportation logic accordingly.
  1. Server-side Teleportation Logic:
  • Upon receiving the “NotificationClicked” event, the server checks if the player triggering the event has sufficient permissions (Moderator or higher).
  • If the player has the required permissions, the server attempts to locate the target player using their name.
  • Once the target player is identified, the server verifies that both the admin and the target player have their characters loaded and accessible.
  • If all conditions are met, the server teleports the admin to the position of the target player.
  1. Potential Bugs and Considerations:
  • Missing Player Characters: One potential bug could occur if either the admin or the target player’s character is not loaded or accessible at the time of teleportation. Ensure that characters are properly loaded before attempting to teleport.
  • Insufficient Permissions Handling: If a player attempts to trigger the teleportation without having the necessary permissions, the script should handle this gracefully. Currently, the script warns about insufficient permissions, but you might want to implement a more user-friendly notification.
  • Target Player Not Found: If the target player specified in the event is not present in the game, the teleportation will fail. Consider providing feedback to the admin in such cases to indicate that the target player could not be located.
  • Client-Server Communication: Ensure that the client-side code responsible for triggering the “NotificationClicked” event is functioning correctly and is synchronized with the server-side logic. Any discrepancies between client and server behavior could lead to unexpected results.

What You Need To Ensure

  • Make sure you’ve set up the remoteEvent correctly to handle both sending notifications and receiving teleportation requests.
  • Also, PLEASE make sure the client-side script responsible for handling notification clicks is properly implemented to trigger the server event with the correct parameters.

Other Alternative Approaches and Potential Fixes

  1. Use RemoteFunction for Teleportation Confirmation:
  • Instead of relying on a notification click event to trigger teleportation, you can use a RemoteFunction to request confirmation from the admin before teleporting. This way, the admin can choose whether to accept or decline the teleportation request.
  • When the admin receives the notification, they can click on it to open a dialog box with options to accept or decline the teleportation.
  • If the admin accepts, the client-side script can invoke the RemoteFunction with the target player’s name, and the server-side script handles the teleportation accordingly.
  1. Implement a Teleportation Command:
  • Instead of relying on notifications, you can implement a command that allows admins to teleport directly to a player by typing a specific command in the chat.
  • Admins can use commands like “!tp PlayerName” to teleport to the specified player.
  • Implement server-side logic to validate permissions and ensure that only admins can use the teleportation command.
  1. Enhanced Error Handling and Feedback:
  • Improve error handling in the script to provide more informative feedback to admins in case of failures.
  • Instead of just warning about errors, provide specific messages indicating the reason for failure, such as “Player not found” or “Teleportation destination obstructed.”
  1. Teleport to Player’s Last Known Position:
  • If the direct teleportation to the player fails due to character loading issues, you should REALLY consider teleporting the admin to the player’s last known position instead.
  • Store the last known positions of players periodically and use this information for teleportation if the player’s character is not accessible at the time of the request.
  1. Implement Cooldowns and Limits:
  • Just to prevent abuse or excessive teleportation requests, you can for sure implement cooldown periods or limits on how frequently admins can teleport to players.
  • This can help inside maintaining balance and fairness in the game environment, lol.
  1. Logging and Analytics:
  • You can also implement logging functionality to track teleportation requests, including timestamps, requester details, and teleportation outcomes.
  • Then, analyze the logged data to identify patterns, potential issues, or areas for improvement in the teleportation system.

Pseudo Code Examples

  1. Check Character Availability:

    • Pseudo Code:
    • if admin.Character is not null and admin.Character.HumanoidRootPart is not null and targetPlayer.Character is not null and targetPlayer.Character.HumanoidRootPart is not null:
          // Proceed with teleportation logic
      else:
         // Handle missing characters gracefully (e.g., display a warning message)
      
      
  2. Enhanced Permissions Handling:

    • Pseudo Code:
    • if returnPermissions(player) >= 1:
          // Admin has sufficient permissions, proceed with teleportation logic
      else:
          // Display a user-friendly message indicating insufficient permissions
      
  3. Handle Missing Target Player:

    • Pseudo Code:
    • if targetPlayerObject is not null:
          // Proceed with teleportation logic
      else:
          // Notify admin that the target player could not be located
      
  4. Ensure Client-Server Synchronization:

    • Pseudo Code (Client-Side):
    • // Trigger server-side event "NotificationClicked" with action = "TeleportToPlayer" and 
      targetPlayerName
      
    • Pseudo Code (Server-Side):
    • OnServerEvent "NotificationClicked" is triggered:
          if action == "TeleportToPlayer":
             // Proceed with teleportation logic based on the provided target player name
      

That’s a few of them, there are a lot more examples!

Test this revised script in your game environment.

Let me know if you encounter any issues or if you need more assistance!! :grin:
(so sorry for the large chunk of text again LOL, and feel free to mark this post as the Solution if it helped/worked!)
1 Like

Thank you so much, really appreciate it!

1 Like

I have inserted this script and it does not work, i have also checked the dev console and found no error logs.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.