The code i made that didnt work
function OnClick()
game.StarterGui.ScreenGui.TextLabel.Text = "works"
end
script.Parent.ClickDetector.MouseClick:connect(OnClick)
The code i made that didnt work
function OnClick()
game.StarterGui.ScreenGui.TextLabel.Text = "works"
end
script.Parent.ClickDetector.MouseClick:connect(OnClick)
Hello, I made a new script for you, I see that the other persons script works so I made a new one where you can change the text anytime very quickly!
Script in ClickDetector:
local replicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.MouseClick:Connect(function()
replicatedStorage:FindFirstChild("ChangeText"):FireAllClients("Works") -- Change to the text you want!
end)
LocalScript in TextLabel:
local replicatedStorage = game:GetService("ReplicatedStorage")
replicatedStorage:FindFirstChild("ChangeText").OnClientEvent:Connect(function(text)
script.Parent.Text = tostring(text)
end)
Really simple.
function OnClick(player: Player)
player.PlayerGui.TextLabel.Text = "works"
end
script.Parent.ClickDetector.MouseEnter:Connect(OnClick)
You're changing it so it shows up when they respawn or anyone.
MouseEnter (NOT MOUSECLICK!) has a player argument to get the player.
He is looking for it on click, and MouseClick does have the player argument.
Sorry but your script didnt work when I used it, I dont know whats wrong with it.
Can you show me how to make that EVERY player in the server can see the text?
you didn't say that. clearly didn't. next time say that.
The fastest way to do this would actually be via the use of remotes. Its finicky to use a server sided script to change a players UI.
First create a remote event within ReplicatedStorage, name it whatever you want. I went with ClickRemote.
Inside of a local script inside of the text box your code should look like this:
local Remote = game.ReplicatedStorage.ClickRemote
Remote.OnClientEvent:Connect(function()
script.Parent.Text = "Text to set to"
end)
Inside of the server script you can setup your code to detect clicks and fire the remote towards the player that clicks:
local ClickDetector = script.Parent.ClickDetector
local Remote = game.ReplicatedStorage.ClickRemote
local function HandleAClick(PlayerThatClicked)
Remote:FireClient(PlayerThatClicked)
end
ClickDetector.MouseClick:Connect(HandleAClick)
This will change the text of the UI
Can you show me how to make it so every player can see the text?
Change :FireClient(PlayerThatClicked) to :FireAllClients()
Alright, it worked, tysm! Idk how to put it as the answer bc it seems to be removed but ty it worked for me!
Just one question, how can i make it that the text has the name of the player who clicked the button?
Server Script: Remote:FireAllClients(PlayerThatClicked.)
This is gonna be harder to explain but fits in well with what Matt said as an answer, you could change the "Works" in :FireAllClients() to (In my script) PlayerThatClicked.Name and the local script needs function() changing to function(playerName) and then script.Parent.Text = playerName .. " clicked the button"
Alr it worked, tysm!
hey you! have you ever heard of enes? if you are in trouble, better call enes!
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
There would be no use to using tostring when its already sending text
Yea just in case
Just in case they send like a number? I mean it won't do anything really at all
As good as the scripting itself is, tostring isn't required to be used and just wastes a second of typing.
It doesn't really matter bro
Protogen_Dev showed me how to change the code to what I wanted which was to put the name of the Player who clicked it as the text, so I accept this answer. Also ty Protogen_Dev for showing me how to change the code, btw im new to scripting