The code i made that didnt work
1 | function OnClick() |
2 | game.StarterGui.ScreenGui.TextLabel.Text = "works" |
3 | end |
4 | 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:
1 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 |
3 | script.Parent.MouseClick:Connect( function () |
4 | replicatedStorage:FindFirstChild( "ChangeText" ):FireAllClients( "Works" ) -- Change to the text you want! |
5 | end ) |
LocalScript in TextLabel:
1 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 |
3 | replicatedStorage:FindFirstChild( "ChangeText" ).OnClientEvent:Connect( function (text) |
4 | script.Parent.Text = tostring (text) |
5 | end ) |
Really simple.
1 | function OnClick(player: Player) |
2 | player.PlayerGui.TextLabel.Text = "works" |
3 | end |
4 | 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.
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:
1 | local Remote = game.ReplicatedStorage.ClickRemote |
2 |
3 | Remote.OnClientEvent:Connect( function () |
4 | script.Parent.Text = "Text to set to" |
5 | end ) |
Inside of the server script you can setup your code to detect clicks and fire the remote towards the player that clicks:
1 | local ClickDetector = script.Parent.ClickDetector |
2 | local Remote = game.ReplicatedStorage.ClickRemote |
3 |
4 | local function HandleAClick(PlayerThatClicked) |
5 | Remote:FireClient(PlayerThatClicked) |
6 | end |
7 |
8 | ClickDetector.MouseClick:Connect(HandleAClick) |
This will change the text of the UI
hey you! have you ever heard of enes? if you are in trouble, better call enes!