Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me on my script? It doesn't seem to teleport me. I need a fix now

Local Script

local button = script.Parent
button.MouseButton1Click:Connect(function()
end)

Server Script

game.ReplicatedStorage.HumanEvent.OnServerEvent:Connect(function()
	game:GetService("Players").HumanoidRootPart = CFrame.new(Vector3.new(-144.74, -2.641, 46.31))
end)

`

4 answers

You had the script listen for mouse button 1 click events but you forgot to fire the event to the server.

local button = script.Parent
	button.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.HumanEvent.FireServer()
end)

1 comment

0

it won't work

Hey there your script won't work because of these problems:

First: Xviperlink is kinda right you have to fire the server Second: You're trying to move the service player not an actual player Thrid: Your method is bad

Here's a quick fix for you tho:

localscript

local button = script.Parent

button.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").HumanEvent.FireServer()
end)

serverscript

game.ReplicatedStorage.HumanEvent.OnServerEvent:Connect(function(player)
    workspace[player.Name]:MoveTo(Vector3.new(-144.74, -2.641, 46.31)
end)

So ye this should work try it.

2 comments

0

Ummm you may have spelled 'third' wrongly.. haha

0

At least i posted a working fix..haha

Alright, to add on to Zetruis. He was kind of right, though he forgot that to fire the event you need to use

:FireServer()

instead of

.FireServer()

A pretty simple fix.

IMO, the code should look more like this:

Button Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local button = script.Parent
local humanEvent = ReplicatedStorage:WaitForChild("HumanEvent")

	button.MouseButton1Click:Connect(function()
		humanEvent:FireServer()
	end)

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local humanEvent = ReplicatedStorage:FindFirstChild("HumanEvent")

if humanEvent then
	humanEvent.OnServerEvent:Connect(function(player)
		if player.Character and player.Character.Parent == game.Workspace then
			player.Character:MoveTo(Vector3.new(-144, -2, 46)) -- Or wherever
		end
	end)
else -- optional
	warn("Some message about HumanEvent being nil or misnamed, etc")
end

Optionally, you can teleport characters with player.Character:SetPrimaryPartCFrame(cf) if you need to specify which direction they end up facing, but you lose the automatic height search functionality of MoveTo, so you have to do your own checks to make sure you're sending the player to an open space where they will fit. Some raycasts may be necessary. This is more work, but gives developers more control.

This discussion is preserved as it was. New answers, comments, and votes are closed.