Hi!
I am trying to make a script where a player would press a button on a GUI and it will teleport them to the part.
My script is:
local Camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
Camera.CameraType = "Custom"
script.Parent.Parent.Visible = false
plr.CameraMaxZoomDistance = 0.5
plr.CameraMinZoomDistance = 0.5
game.Workspace[plr.Name].HumanoidRootPart.CFrame = game.Workspace.russiaspawn.CFrame
end)
The error I get is russiaspawn is not a valid member of Workspace "Workspace"
and it is in workspace.
Can anyone please help? Thank you I appreciate it!
4 Likes
You can do this instead of this :
local Camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
Camera.CameraType = "Custom"
script.Parent.Parent.Visible = false
plr.CameraMaxZoomDistance = 0.5
plr.CameraMinZoomDistance = 0.5
plr:PivotTo(game.Workspace.russiaspawn.CFrame)
end)
And can you show us the part in game (in the explorer) ?
Sure!
But, same error and I put the script in.
Are you sure that russiaspawn is anchored and cancollide == true? If they fall of the workspace then they won’t exist
local workspace = game:GetService("Workspace")
local Camera = game.Workspace.CurrentCamera
local russiaspawn = workspace:FindFirstChild("russiaspawn")
if russiaspawn then
Camera.CameraType = "Custom"
script.Parent.Parent.Visible = false
plr.CameraMaxZoomDistance = 0.5
plr.CameraMinZoomDistance = 0.5
game.Workspace[plr.Name].HumanoidRootPart.CFrame = russiaspawn.CFrame
else
print("russiaspawn not found in Workspace")
end
@FireStrykerAzul
PivotTo is not a valid member of Player "Players.TeamDreams123"
@Halacs2008 Thank you so much! I just changed it
@hollaquetalBRUH That’s pretty much the same script I just used but with some tiny edits-
Did anchoring the part fixed the problem?
1 Like
No, not the whole problem. But it was part of the problem since it just fell and then it just disappeared.
Would you mind providing any scripts that could help? Thanks!
What is the problem now ? fzjiejiogfze
What is the current problem? What kind of error do you get? Or you get no tp?
1 Like
make russiaspawn anchored and cancollide false
1 Like
Is the script you wrote a local or a server (Normal) script?
The script must be local, and detect the mousebuttonclick
then, it must FireClient a remoteevent, that teleports the player with the humanoidrootpart
Local Script
No teleportation
Already done!
And that’s what I’m stuck on.
Got the issue I think. Let me type it.
@TeamDreams123 hope this fixes the issue
So your problem is: no remoteEvent.
When the click event happens, you should trigger a remoteEvent.
script.Parent.MouseButton1Up:Connect(function()
game.ReplicatedStorage.TeleportEvent:FireServer() --TeleportEvent is a remoteEvent inside of ReplicatedStorage
end)
Because the localscript can’t handle that change, you have to use a serverScript.
So inside of a normal script, say something like:
game.ReplicatedStorage.TeleportEvent.OnServerEvent:Connect(function(player)
local russiaspawn = --the part
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.CFrame = russiaspawn.CFrame
end)
Make sure your parts are in the right area. Also, why do you need the camera? Can you send me a screenshot of your workspace so I could see russiaspawn
?
Make sure it’s not case sensitive!!
Still does not work, I think my roblox is broken…
Can you send picture? I don’t get the issue.
Try this :
local Camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
Camera.CameraType = "Custom"
script.Parent.Parent.Visible = false
plr.CameraMinZoomDistance = 0.5
plr.CameraMaxZoomDistance = 0.5
plr:PivotTo(game.Workspace.russiaspawn.CFrame)
end)
For the explaination, you can’t reduce the CameraMaxZoomDistance before the CameraMinZoomDistance !
Have a nice day !
Do you understand that the ‘plr’ variable is under players? Thats where I’m stuck! And also the CameraMin/MaxZoomDistance does not matter-
1 Like