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

How do I make this script just teleport the player, not all players?

Asked by 4 years ago

How do I make this script just teleport the player and not all the players? I need help. I know this is not a request site but this is the only place where I can ask. This is a normal Script

local BuggyLoc = CFrame.new(-106.428, 121.84, -194.854)

script.Parent.MouseButton1Click:connect(function(Tele)
    for i, v in pairs(game.Players:GetPlayers()) do
    v.Character:SetPrimaryPartCFrame(BuggyLoc)
    end
end)

0
Is it teleporting you to the right place, even though all players are teleporting. SprinkledFruit101 135 — 4y
0
Yes it is teleporting me to the car's seat, but all players are being teleported there and I don't want that. squidiskool 208 — 4y
0
So basically I think instead of using for i,v in pairs, you can use the parameter in the Tele I'll give an example in my answer. SprinkledFruit101 135 — 4y
0
local BuggyLoc = CFrame.new(-106.428, 121.84, -194.854) clickDetector = script.Parent local function onMouseClick(player) v = player v.Character:SetPrimaryPartCFrame(BuggyLoc) end clickDetector.MouseClick:connect(onMouseClick) FakeWhatWeDontKnow 0 — 4y
0
Oh by the way is this is in a local script? SprinkledFruit101 135 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Well, you're using a script for what seems to be a job cut out for a LocalScript. .MouseButton1Down is meant as something registered on the Client. However, if you use a LocalScript, the teleport will only be registered on the client. We need to use a RemoteEvent to register it on the server. You can read more about RemoteEvents and Server stuff here. First, you need to create a RemoteEvent in the ReplicatedStorage of your game. Name it something.

This is what your local script should look like.

script.Parent.MouseButton1Click:connect(function()
    game.ReplicatedStorage.TeleportEvent:FireServer()
end)

This is what your server script should look like, put it in the ServerScriptStorage.

game.ReplicatedStorage.TeleportEvent.OnServerEvent:connect(function(plr)
    local BuggyLoc = CFrame.new(-106.428, 121.84, -194.854)
    plr.Character.SetPrimaryPartCFrame(BuggyLoc)
end)

Hope that helped out, consider accepting this answer. If not, comment below and I'll be sure to help out further.

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

Assuming this is a server script and not a local script

local BuggyLoc = CFrame.new(-106.428, 121.84, -194.854)

script.Parent.MouseButton1Click:connect(function(Tele)
    for i, v in pairs(game.Players:GetPlayers()) do
        if v.Character then --Checking if the player has a Character
            if v.Character == script.Parent.Parent then --Checking if this player's character is the player's character
                    v.Character:SetPrimaryPartCFrame(BuggyLoc)
            end
        end
    end
end)

Answer this question