I am trying to make a script that swaps the position between the player and an NPC.
Nothing happens when it runs, it does not error, it is not stopped, and no if statement prevents it, I even put a print at the end, it says it worked, I printed the result positions and they were how they are supposed to be, but nothing happens.
I’ve tried using different methods to move the player and NPC, and also tried commenting certain parts of the code to see if they were the problem, but got no results.
This is an example of the code I used.
local npc = game.Workspace.Dummy
local cframe1 = npc.HumanoidRootPart.CFrame
local cframe2 = game.Workspace.Fro_ZinOvr.HumanoidRootPart.CFrame
game.Workspace.Fro_ZinOvr.HumanoidRootPart.CFrame = cframe1
npc.HumanoidRootPart.CFrame = cframe2
Well, if this is a Server Script, your script is likely running very early, which would result in the Player not existing yet, Server Scripts do not wait for the Player to join the game.
local char = script.Parent
local keybind = Enum.KeyCode.E
function swap(input)
if input.KeyCode == keybind then
game.Workspace.Event:FireServer()
end
end
Not really a good idea to be taking it directly from the workspace, with the Player, you can easily access it with .Character, where you can directly access it. so it doesnt really make sense.
Another thing is that instead of accessing the HumanoidRootPart to get the CFrame value, you should instead use GetPivot which is a CFrame of the model.
Also, RemoteEvent’s that fire to the Server have a Player variable.
local UIS = game:GetService(“UserInputService”)
local char = script.Parent
local keybind = Enum.KeyCode.E
function swap(input)
if input.KeyCode == keybind then
game.Workspace.Event:FireServer()
end
end
UIS.InputBegan:Connect(swap)