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

How to teleport a player to their tycoon on GUI button click?

Asked by 4 years ago

I am making a tycoon. I have a ScreenGui with a TextButton. When I click on the button, I want the player who clicked to teleport to their tycoon. In my tycoon kit, I have a StringValue and it's value is the player who owns that tycoon. I want to find the tycoon kit with the name of the player who clicked the GUI button, and teleport there but no idea how to script it.

P.S. If they do not have a tycoon, just do nothing.

0
Sorry if this is non-descriptive, but I cannot find any code or make any code that works. funnytevinn -5 — 4y
0
What is the path to the tycoon kits? Are they parented to the same instance? compUcomp 417 — 4y
0
Also, what's the path to the StringValue inside the tycoon? compUcomp 417 — 4y

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago

You would use a RemoteEvent to handle the actual teleportation. LocalScript parented to gui button:

local teleportEvent = game:GetService("ReplicatedStorage"):WaitForChild("TeleportEvent")
script.Parent.MouseButton1Click:Connect(function ()
    teleportEvent:FireServer()
end)

Script in SSS or Workspace, either one:

local RS = game:GetService("ReplicatedStorage")
local teleportEvent = Instance.new("RemoteEvent")
local tycoons = workspace.Tycoons
teleportEvent.OnServerEvent:Connect(function (p)
    for i, v in pairs(tycoons:GetChildren()) do
        if v.Owner.Value == p.Name then -- 
            p.Character:SetPrimaryPartCFrame(v.Spawn.CFrame + Vector3.new(0, 4, 0)
            break
        end
    end
end)

You'll have to change a few things. Since you didn't respond to my comments, I assumed that your tycoons were in workspace.Tycoons, that the path to the owner StringValue was tycoon.Owner, and the spawn platform was tycoon.Spawn. You'll have to tweak those, since those names are completely figurative.

0
There's an error. "Infinite yield possible on 'ReplicatedStorage:WaitForChild("TeleportEvent")'" funnytevinn -5 — 4y
Ad

Answer this question