Hello Developers! I am stuck with this script, because I want the player to click a UI button, then the button goes invisible. I want this to happen for only one player; The player who clicks it. I am not sure how to make thing happen now only for the player who clicks it because it is in a server script. Do I need to access the player UI or something? If you give me a script, only change the bit that I think would affect all players, which is this bit.
if touching == true then
tb.MouseButton1Click:Connect(function()
tb.Visible = false
The full script is posted below. Some of it might not be needed, but look for the bit I posted above.
local Distance = 10
local talking = false
local players = game:GetService("Players")
local player = players.LocalPlayer
local startergui = game:GetService("StarterGui")
local screengui = startergui.ScreenGui
local frame = screengui.Frame
local nf = frame.NextFrame
local nb = nf.NextButton
nf.Visible = false
nb.Visible = false
frame.Position = UDim2.new(0, 0,1.2, 0)
local talkable = true
local touching = false
while wait()do
for i,v in pairs(workspace:GetChildren()) do
if game.Players:FindFirstChild(v.Name) then
if(v.PrimaryPart.Position - script.Parent.Position).magnitude <= Distance then
if talking == false then
touching = true
local character = v
local player = players:GetPlayerFromCharacter(character)
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local frame = screenGui:WaitForChild("Frame")
local tb = frame:WaitForChild("TalkButton")
frame:TweenPosition(UDim2.new(0, 0,0.73, 0), "Out", "Back")
local nextframe = frame:WaitForChild("NextFrame")
local nextbutton = nextframe:WaitForChild("NextButton")
local talktext = frame:FindFirstChild("TalkText")
if talkable == true then
if touching == true then
tb.MouseButton1Click:Connect(function()
tb.Visible = false
end)
end
end
end
else
if talking == false then
touching = false
local character = v
local player = players:GetPlayerFromCharacter(character)
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local frame = screenGui:WaitForChild("Frame")
local tb = frame:WaitForChild("TalkButton")
local nextframe = frame:WaitForChild("NextFrame")
local nextbutton = nextframe:WaitForChild("NextButton")
local talktext = frame:FindFirstChild("TalkText")
frame:TweenPosition(UDim2.new(0, 0,1.2, 0), "Out", "Back")
end
end
end
end
end
Thank you to everyone who helps and merry christmas!
You put this in a server script, so every player can see the changes. If you change the value (visibility) of textButton in the local script, only the player who clicked on it will see the changes.
Place a local script in your ScreenGui and define your textButton will be clicked.
-- Example Code
--Be sure localScript is in your ScreenGui
local ScreenGui = script.Parent
local TextButton = ScreenGui:WaitForChild("TextButton") -- Your textButton, which will be clicked
TextButton.MouseButton1Click:Connect(function()
TextButton.Visible = false
-- your code
end)
Hello! Thank you for your reply! I tested it with my brother, and even though it was in a server script, when I clicked it, it only disappeared for me as intended
I don’t know why, at all, because server scripts control the whole server, but I guess my problem is solved.
I actually can’t believe I didn’t think of what you were saying, because I don’t need to continue it from the event of the server script, and you think very logically!
local part = workspace:WaitForChild("Part") --change this reference
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local screengui = playergui.ScreenGui
local frame = screengui.Frame
local nf = frame.NextFrame
local nb = nf.NextButton
local tt = frame.TalkText
nf.Visible = false
nb.Visible = false
frame.Position = UDim2.new(0, 0, 1.2, 0)
local distance = 10
local talking = false
local talkable = true
while task.wait()do
for _, plr in ipairs(players:GetPlayers()) do
local char = plr.Character
local hrp = char:FindFirstChild("HumanoidRootPart")
if (hrp.Position - part.Position).magnitude <= distance then
if not talking then
local playerGui = plr:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local frame = screenGui:WaitForChild("Frame")
local nextframe = frame:WaitForChild("NextFrame")
local nextbutton = nextframe:WaitForChild("NextButton")
local talktext = frame:WaitForChild("TalkText")
frame:TweenPosition(UDim2.new(0, 0, 0.73, 0), "Out", "Back", 1)
if talkable then
uis.InputBegan:Connect(function(key, processed)
if processed then
return
end
if key.KeyCode == Enum.KeyCode.E then
nf.Visible = true
nb.Visible = true
tt.Text = "Hello!"
nb.MouseButton1Click:Connect(function()
tt.Text = "Bye!"
end)
end
end)
end
elseif talking then
local playerGui = plr:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local frame = screenGui:WaitForChild("Frame")
local nextframe = frame:WaitForChild("NextFrame")
local nextbutton = nextframe:WaitForChild("NextButton")
local talktext = frame:WaitForChild("TalkText")
frame:TweenPosition(UDim2.new(0, 0, 1.2, 0), "Out", "Back", 1)
end
end
end
end
You’ll need to fix the reference to the part in the workspace at line 1 of the script (I just made one up).