Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing text button text in scripts. How?

I have a local script that says when a text button is clicked then it fires a remote event.

script.Parent.MouseButton1Down:Connect(function()
	if script.Parent.Parent.Parent.RequirementFrame.Visible == false then
		script.Parent.Parent.Parent.RequirementFrame.Visible = true
		script.Parent.Parent.Parent.RequirementFrame.Active = true
		game.Workspace.Events.Text:FireServer()
	else
		script.Parent.Parent.Parent.RequirementFrame.Visible = false
		script.Parent.Parent.Parent.RequirementFrame.Active = false
	end
end)

And then I have a script of when the remote event is fired.

script.Text.OnServerEvent:Connect(function(plr)
	local NeededJump = plr.Settings.NJump
	local NeededSpeed = plr.Settings.NSpeed
	local NeededStrength = plr.Settings.NStrength
	
	game.StarterGui.RequirementsGui.RequirementFrame.Strength.Text = "Strength: "..NeededStrength.Value
	game.StarterGui.RequirementsGui.RequirementFrame.Jump.Text = "Jump: "..NeededJump.Value
	game.StarterGui.RequirementsGui.RequirementFrame.Speed.Text = "Speed: "..NeededSpeed.Value
end)

The OnServerEvent script is not a LocalScript. I have checked every word in both scripts and neither of them have typos. I used Print to check if it stopped at a certain line but it didn't. It doesn't give any errors in the output. The problem is not a typo or anything, it just won't change the text. Please help?

1 comment

0

LocalScripts can't even use OnServerEvent. It's not even listed in the available events as you type. Are you trying to start a riot or something?

2 answers

✓ Accepted answer

The server can't see the contents of PlayerGui, if the player who is firing to the server wants to change its own guis, then we simply need to change the the localplayer's version of the gui in PlayerGui.

local plr=game.Players.LocalPlayer

script.Parent.MouseButton1Down:Connect(function()
    if script.Parent.Parent.Parent.RequirementFrame.Visible == false then
        script.Parent.Parent.Parent.RequirementFrame.Visible = true
        script.Parent.Parent.Parent.RequirementFrame.Active = true
        game.Workspace.Events.Text:FireServer()
    else
        script.Parent.Parent.Parent.RequirementFrame.Visible = false
        script.Parent.Parent.Parent.RequirementFrame.Active = false
    end
	
    local NeededJump = plr.Settings.NJump
    local NeededSpeed = plr.Settings.NSpeed
    local NeededStrength = plr.Settings.NStrength

    plr.PlayerGui.RequirementsGui.RequirementFrame.Strength.Text = "Strength: "..NeededStrength.Value
    plr.PlayerGui.RequirementsGui.RequirementFrame.Jump.Text = "Jump: "..NeededJump.Value
    plr.PlayerGui.RequirementsGui.RequirementFrame.Speed.Text = "Speed: "..NeededSpeed.Value
end)

If you are trying to change EVERYONE'S gui then in the server script, we then need to fire to all children and have them change their own guis, but we can also keep changing the StarterGui so that when they respawn it will remain.

LocalScript

script.Parent.MouseButton1Down:Connect(function()
    if script.Parent.Parent.Parent.RequirementFrame.Visible == false then
        script.Parent.Parent.Parent.RequirementFrame.Visible = true
        script.Parent.Parent.Parent.RequirementFrame.Active = true
        game.Workspace.Events.Text:FireServer()
    else
        script.Parent.Parent.Parent.RequirementFrame.Visible = false
        script.Parent.Parent.Parent.RequirementFrame.Active = false
    end
end)

remote.OnClientEvent:Connect(function(s,j,speed)
	plr.PlayerGui.RequirementsGui.RequirementFrame.Strength.Text = "Strength: "..s
    plr.PlayerGui.RequirementsGui.RequirementFrame.Jump.Text = "Jump: "..j
    plr.PlayerGui.RequirementsGui.RequirementFrame.Speed.Text = "Speed: "..speed
end)

Server

script.Text.OnServerEvent:Connect(function(plr)
    local NeededJump = plr.Settings.NJump
    local NeededSpeed = plr.Settings.NSpeed
    local NeededStrength = plr.Settings.NStrength

    game.StarterGui.RequirementsGui.RequirementFrame.Strength.Text = "Strength: "..NeededStrength.Value
    game.StarterGui.RequirementsGui.RequirementFrame.Jump.Text = "Jump: "..NeededJump.Value
    game.StarterGui.RequirementsGui.RequirementFrame.Speed.Text = "Speed: "..NeededSpeed.Value

	remote:FireAllClients(NeededStrength.Value,NeededJump.Value,NeededSpeed.Value)
end)

When you make changes to the contents of StarterGui, these changes are applied only when the player resets.

You should be changing the contents of PlayerGui. The contents of StarterGui are cloned locally into each player's PlayerGui. The changes made there apply immediately since it's the GUIs the player is currently seeing.

PlayerGui is found inside the player so game.Players.playerhere.PlayerGui

1 comment

0

It says that playerhere does not exist

This discussion is preserved as it was. New answers, comments, and votes are closed.