Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
it won't work VitroxVox 884 — 4y
Ad
Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago

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.

0
Ummm you may have spelled 'third' wrongly.. haha XviperIink 428 — 4y
0
At least i posted a working fix..haha VitroxVox 884 — 4y
Log in to vote
0
Answered by
Lucke0051 165
4 years ago

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.

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Answer this question