A part of my doesn't work

Hi,
a part of my script does not work:

local Player = game:GetService("Players").LocalPlayer
local shopkeeper2 = game.Workspace.shopkeeper2
local cam = workspace.CurrentCamera

script.Parent.Triggered:Connect(function(player)
	player.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.thisNameOther.Position)
	shopkeeper2.HumanoidRootPart.CFrame = CFrame.new(workspace.shopkeeperto.Position)
	
	cam.CameraType = "Fixed"
	cam.Focus = shopkeeper2.CFrame
	
	local Rage = Player.PlayerGui.Rage
	Rage.Enabled = true
	
	task.wait(1)

	task.wait(1)
	
	local char = player.Character or player.CharacterAdded:Wait(0)
	local Humanoid = char.Humanoid
	
	Humanoid.Health = 0
end)

only

script.Parent.Triggered:Connect(function(player)
	player.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.thisNameOther.Position)

works

local Player = game:GetService("Players").LocalPlayer

local shopkeeper2 = workspace.shopkeeper2

local camera = workspace.CurrentCamera

script.Parent.Triggered:Connect(function(player)
	local character = player.Character
	if not character then return end

	character:PivotTo(CFrame.new(workspace.thisNameOther.Position))
	shopkeeper2:PivotTo(CFrame.new(workspace.shopkeeperto.Position))


	print("Teleported") -- Does this print?

	cam.CameraType = Enum.CameraType.Fixed
	cam.Focus = shopkeeper2.CFrame

	print("Set camera") -- Does this print?

	local rage = Player.PlayerGui.Rage
	rage.Enabled = true

	print("Enabled GUI") -- Does this print?

	task.wait(2)

	character.Humanoid.Health = 0
	print("Killed") -- Does this print?
end)
2 Likes

just Teleported printed and it says CFrame is not a valid member of Model “Workspace.shopkeeper2”

Instead of .CFrame use :GetPivot() this function will work for Models and Parts similarly

now it prints set camera and it says Workspace.TeleporterOutShop .ProximityPrompt.Script:22: attempt to index nil with ‘PlayerGui’

local rage = Player.PlayerGui.Rage

That errors means in this line the variable Player is nil. if we go to where Player is defined we see that it is trying to get the LocalPlayer, which doesn’t exist for the Server, therefor nil. Move your code from a Script (server-side) to a LocalScript (client-side)

local Player = game:GetService("Players").LocalPlayer

in the local script it does not work

Could you explain why it does not work? it is most helpful if you tell us:

  1. Post the script you are working on
  2. Explain what you expect to happen
  3. Explain what really happens, and include error messages