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

Variable within a Variable Help?

So I need some help with setting a variable to a different variable. Here's the code block:

I am trying to get the value of Shipsname (Which is the models name that is in Workspace) and put it into another variable called Object. This models name varies and so I need a variable to represent it.(Called Shipsname)

Shipsname = game.Players.LocalPlayer.Character.Shipsname--Working on this
Camera = game.Workspace.CurrentCamera
Object = game.Workspace.Shipsname.BodyKit.Grok
Player = script.Parent.Humanoid
Camera.CameraSubject = Object
Camera.CameraType=3
while true do
wait()
	if Player.Sit == false then
	Camera.CameraSubject = Player
	script:Remove()
	end
end

Help is appreciated. Sorry if its confusing. I'll try and clear up any questions you may have.

2 answers

✓ Accepted answer
Shipsname = game.Players.LocalPlayer.Character.Shipsname--Working on this and Change the name of Shipsname to ShipsName
Camera = game.Workspace.CurrentCamera
Object = game.Workspace[Shipsname.Name].BodyKit.Grok
Player = script.Parent.Humanoid
Camera.CameraSubject = Object
Camera.CameraType=3
while wait() do
    if not Player.Sit then
    Camera.CameraSubject = Player
    script:Remove()
    end
end

Edited again.

9 comments

0

You changed the while loop but that doesn't have much to do with the variable issue.

0

I didn't only change that.

0

I'll try and re-explain. The model name is going to change. Therefore I need a variable that changes with it. In this case I want that variable to be "Shipsname". The problem is, the program thinks that when I say game.Workspace.Shipsname, it things the model is called "Shipsname" when its actually something that the variable represents.

0

Done, I edited.

0

I got this error: 16:31:08.162 - Workspace.Player.CameraChange:17: bad argument #2 to '?' (string expected, got userdata) 16:31:08.164 - Script 'Workspace.Player.CameraChange', Line 17 16:31:08.165 - Stack End

0

Sorry, That was an object value not a string. I found my mistake.

0

Ok it didn't work the first time so I just changed the Shipsname.Name to Shipsname.Value. After that, things worked smoothly so thanks alot!

0

You never said that Shipsname was a value.

0

Ah, well it was. heh

Why in the world do you want a variable within a variable...?

1 comment

0

I've tried to explain it in the previous answer's comments.

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