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

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

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.

3 comments

0

Sorry if this is non-descriptive, but I cannot find any code or make any code that works.

0

What is the path to the tycoon kits? Are they parented to the same instance?

0

Also, what's the path to the StringValue inside the tycoon?

1 answer

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.

1 comment

0

There's an error. "Infinite yield possible on 'ReplicatedStorage:WaitForChild("TeleportEvent")'"

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