Script Help Please

Hi, so i’m making a piggy like game using alvin blox’s kit. I’ve ran into an issue though with a simple fix that I am struggling with. Basically, I want the first character to be named ducky for my game but that messes up the game for some reason so it has to be named piggy making it named that in the shop. So I assumed I could do a script like this to replace the name?

while true do
game:GetService(‘Players’).LocalPlayer:WaitForChild(‘PlayerGui’)

if PlayerGui.MainGUI.Shop.ClientShop.Template.Title.Text == “Piggy”
then PlayerGui.MainGUI.Shop.ClientShop.Template.Title.Text = “Ducky”
end
end

It isn’t working though. Help please.

The output error would be useful and the good indentation. Also provide a screenshot of the gui if there are no error.
Edit: You’re missing a wait()

First off you need to assign the playergui to a variable

PlayerGui = game:GetService(‘Players’).LocalPlayer:WaitForChild(‘PlayerGui’)

It’s probably connected to another name somewhere else in the game, also you should throw a wait() inside of the while true do, if it isn’t crashing your studio I’m very surprised.

Edit: where is your script located, and what type of script

1 Like

The error is 07:22:26.097 - Workspace.Script:2: attempt to index nil with ‘WaitForChild’

wait() shouldn’t really be used in scenarios like this.

LocalPlayer is for LocalScripts, not Scripts.
Also, why are you using a loop for this?

1 Like

idk i’m new to scripting sorry

I’m not sure what it’s meant to do, but you need to use a LocalScript for the client (including UI).

If you’re trying to change ‘Piggy’ to ‘Ducky’, don’t worry about the scripting aspect of it (assuming you just want to change the default character, I’m kind of confused at this point). You can change the text of a TextLabel/TextButton, etc here:
image

If you’re following a tutorial series, make sure to just make it exactly how the video does it, then if you want to, tamper with things later on once you’ve finished creating it exactly how it was meant to be done. Make sure you’re not just trying to freestyle your way through it with limited knowledge of coding.

I know this. But basically, it automatically edits it to the name in the shop and I want to make sure any name piggy is changed.

I actually got the source code from him, and haven’t changed anything. The only thing i’m trying to change is the name of the piggy, which isn’t possible as i’ve watched them all.

Assuming you’re trying to replace all occurrences of something, you could do this through the command line. Your script is going to run every time the server starts, and if I’m interpreting it correctly, you just want ‘Piggy’ changed.

for _, descendant in pairs(path.to.GUIs:GetDescendants()) do if descendant:IsA("TextButton") or descendant:IsA("TextLabel") then if descendant.Text == "Piggy" then descendant.Text == "Ducky" end end end

You’ll need to change path.to.GUIs to wherever your UI is located. For example, if they were located in StarterGui:

for _, descendant in pairs(game:GetService("StarterGui"):GetDescendants()) do if descendant:IsA("TextButton") or descendant:IsA("TextLabel") then if descendant.Text == "Piggy" then descendant.Text == "Ducky" end end end

Command Bar


Or, if that’s not appearing at the bottom of Studio, you’ll need to enable it.
image

If this is still not what you want, you might need to provide a reference.

I’ll test this out, thanks! ;;;;;;;

Still isn’t working for some reason, I tried changing it to StarterGui.MainGui.Shop.ClientShop.Template.Title.Text
idk if i did that right though

That wouldn’t do anything.

If that’s the only path you want to use, use this:

for _, descendant in pairs(game:GetService("StarterGui").MainGui:GetDescendants()) do if descendant:IsA("TextButton") or descendant:IsA("TextLabel") then if descendant.Text == "Piggy" then descendant.Text == "Ducky" end end end

This will work for its intended function, but this seems like an exercise in futility

I would imagine there are many other scripts within this template that relies upon the fact that objects are named ‘Piggy’.

@ItzGpYt I would highly recommend that you:

  1. Follow whatever tutorial this is from start to finish so you understand what you’re changing and how to do it
  2. Read through each script in its entirety, and look to see if it references/searches for any GameObjects named ‘Piggy’ - you would need to change each of these instances, as well as altering the script(s) to look for ‘Ducky’

I just fixed this by naming the character ducky, then having a timer for 30 seconds then changes it to piggy so the game loads but in the store it says ducky.