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.
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.