script.Parent.MouseButton1Click:Connect(function()
local newtitle = script.Parent.Parent.TextBox.Text
local plr = script.Parent.Parent.Parent.Parent.Parent
local standnumbertochange = script.Parent.Parent.StandToChange.Value
local stand = game.Workspace.Stands:FindFirstChild(standnumbertochange)
stand.TitleName.Value = newtitle
print(plr.Name.." has changed the title name of his/her stand! It was changed to "..script.Parent.Parent.TextBox.Text.."!")
standnumbertochange = 0
script.Parent.Parent.TextBox.Text = ""
end)
and the error in the console says “12:45:09.622 Players.Royce_inator.PlayerGui.TitleChanger.Frame.TextButton.Script:6: attempt to index nil with ‘TitleName’”
Could you screenshot the explorer? It’s hard to help without context.
And next time please format your code using triple backticks. I’ll do it for you here:
Raw
```lua
script.Parent.MouseButton1Click:Connect(function()
local newtitle = script.Parent.Parent.TextBox.Text
local plr = script.Parent.Parent.Parent.Parent.Parent
local standnumbertochange = script.Parent.Parent.StandToChange.Value
local stand = game.Workspace.Stands:FindFirstChild(standnumbertochange)
stand.TitleName.Value = newtitle
print(plr.Name.." has changed the title name of his/her stand! It was changed to "..script.Parent.Parent.TextBox.Text.."!")
standnumbertochange = 0
script.Parent.Parent.TextBox.Text = ""
end)
```
I recommend making your variable names a little bit easier to read and more consistent. Your code should look a bit more like this:
-- Easier way to get the Player (only works in Local Scripts)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
-- Variables are easier to read with camelCase
local newTitle = script.Parent.Parent.TextBox.Text
local standNumberToChange = script.Parent.Parent.StandToChange.Value
local stand = game.Workspace.Stands:FindFirstChild(standnumbertochange)
stand.TitleName.Value = newTitle
standNumberToChange = 0
script.Parent.Parent.TextBox.Text = ""
-- Template/formatted string (this only works in Luau, not Lua!)
print(`{player.Name} has changed the title name of his/her stand! It was changed to {newTitle}!`)
end)
heres the code (the script is not a local script):
local player = script.Parent.Parent.Parent.Parent.Parnet
script.Parent.MouseButton1Click:Connect(function()
-- Variables are easier to read with camelCase
local newTitle = script.Parent.Parent.TextBox.Text
local standNumberToChange = script.Parent.Parent.StandToChange.Value
local stand = game.Workspace.Stands:FindFirstChild(standnumbertochange)
stand.TitleName.Value = newTitle
standNumberToChange = 0
script.Parent.Parent.TextBox.Text = ""
-- Template/formatted string (this only works in Luau, not Lua!)
print(`{player.Name} has changed the title name of his/her stand! It was changed to {newTitle}!`)
end)
Well there’s your problem. You can only code GUIs in Local Scripts. So use a LocalScript instead of a Script and there shouldn’t be any errors. If this solved your problem, please mark the post as the solution so the thread can close.
Basically, there is something called the Server and the Client. Every player that joins your game will have their own client. The server cannot see what is on the clients unless of course you tell it with a RemoteEvent. Each GUI is different on each client, which is why you must use scripts that can access the client when editing GUI. Local Scripts happen on each client, unlike normal Scripts.
i cannot use a local script as the script changes a value in workspace, i will try and if that fixes the problem i will mark your post as solution. i will tell you if it works in a minute
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
-- Variables are easier to read with camelCase
local newTitle = script.Parent.Parent.TextBox.Text
local standNumberToChange = script.Parent.Parent.StandToChange.Value
local stand = game.Workspace.Stands:FindFirstChild(standNumberToChange)
stand.TitleName.Value = newTitle
stand.Title.SurfaceGui.TextLabel.Text = newTitle
print(`{player.Name} has changed the title name of his/her stand! It was changed to {newTitle}!`)
standNumberToChange = 0
script.Parent.Parent.TextBox.Text = ""
print("script end")
end)
the script was changed to a local script as well
thank you for your help