Hey IamTewsmrt,
The problem with your script that I first noticed is that you set a variable for the CFrame of the HumanoidRootPart. So, when you set the variable equal to something, it won't change anything about the HumanoidRootPart, it will just change the value that it is holding which is simply the HumanoidRootPart's CFrame. So, below is a good example of what I'm talking about.
####Example A
local cframe = workspace.Part.CFrame;
local other_part = workspace.OtherPart;
cframe = other_part.CFrame;
###As you can see from the above example you have just set the variable equal to something, you haven't mutated the Part itself. If you want to mutate the HumanoidRootPart's properties itself then you need to set a variable for the HumanoidRootPart and simply set it's CFrame equal to the playerCFrame. Also, you need to use the :WaitForChild() method because it takes time for the Player's Character to load. Below is a personal example of what you need to do to make this work.
####Example B
local part = script.Parent;
local root = workspace:WaitForChild("Player1").HumanoidRootPart;
local cframe = root.CFrame;
function touched(hit)
local hum = hit.Parent:FindFirstChild("Humanoid");
if hum then
cframe = CFrame.new(Vector3.new(-50, 12, -973.5));
root.CFrame = cframe;
end
end
part.Touched:Connect(touched);
-- EDIT:
So, apparently it won't work in the game for you. Well, the simple answer to that is because in the game your character isn't named "Player1" it's your actual name and you are trying to get the Character "Player1", which doesn't exist in the game. So, I recommend defining the root and cframe inside of the function after you check if the humanoid exists. However, don't define the root as:
local root = workspace:WaitForChild("Player1").HumanoidRootPart;
rather, define it as:
local root = hit.Parent:WaitForChild("HumanoidRootPart");
##Also, I hope you're using a ServerScript(Normal Script, not a Local Script) for this operation. Well, I hope I helped in one way or another and I hope you have a nice day/night.
~~ KingLoneCat
1 comment
If player is a placeholder name, I could make it a variable to find the player's username.