I'm making a game that needs this. I made the script but somehow it doesn't work when I click it again.
Inside the part (w/ Click Detector) Script:
script.Parent.ClickDetector.MouseClick:Connect(function(player) player:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = true end)
In Starter Gui: StarterGui, ScreenGui, Frame, TextButton, LocalScript
Inside the Local Script:
local player = game.Players.LocalPlayer local target = game.Workspace.TeleportPart script.Parent.MouseButton1Click:connect(function() player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0) player:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = false end)
When you click the "Part" again it doesn't work...Pls Help.
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") game:GetService("Players").PlayerAdded:Connect(function(Player) script.Parent.ClickDetector.MouseClick:Connect(function() -- you cannot use player as an argument because it is not the player that clicked the part, its the mouse. Therefore in this case, you need to learn a more advanced script called remote function. Go to ReplicatedStorage and insert a remoteEvent RemoteEvent:FireClient(Player) end) end)
For the LocalScript:
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer local target = game.Workspace.TeleportPart RemoteEvent.OnClientEvent:Connect(function() -- you fired a request from ServerScript to LocalScript using RemoteEvent. For more details on remote function, please check roblox devforum. player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0) script.Parent.Parent.Parent.Parent.Parent:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = false -- script.Parent.Parent.Parent.Parent.Parent is the player him/herself. How i know this? Go into studio, then click players > playergui > screengui > frame > textbutton and you find your localscript. The localscript is given and placed in player's gui for every player when they join the game end)
Thank you so much guest_2018,but the LocalScript should be
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer local target = game.Workspace.TeleportPart RemoteEvent.OnClientEvent:Connect(function() script.Parent.Parent.Parent.Parent.Parent:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = true -- To make it visible when the Event is fired end)
Inside the text button I added another LocalScript that teleports the player to another part
local player = game.Players.LocalPlayer local target = game.Workspace.TeleportPart script.Parent.MouseButton1Click:connect(function() player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0) player:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = false end)
thankfully it works!!
I didn't know about remote events and thank you for making me learn about it.