Oykko
Oykko

Reputation: 11

How can I change a walkspeed to like a variable

local playerName = OykkoIsBack
Players.(playerName).Character.Humanoid.JumpPower = 100

so I want to set my jump power to the variable that has the players name? im new to roblox scripting and this happened in my output

Expected identifier, got '('

something similar to this happened i wrote this if game.Workspace.IntValue.Value = 0 then print("Value is 0") but i figured this out by adding a another = but this time i can't figure it out so i need someone to help me! really appreciate it if you could help me!

Upvotes: 1

Views: 810

Answers (2)

GalaxyShard
GalaxyShard

Reputation: 306

OykkoIsBack should have double quotes around it, so the first line should be local playerName = "OykkoIsBack". Without the quotes, it is not a string and cannot be assigned to playerName.

The other issue is with Players.(playerName). The syntax for indexing a table in Lua is table[key]. In your case it should be Players[playerName]

Here is the code

local playerName = "OykkoIsBack"
Players[playerName].Character.Humanoid.JumpPower = 100

What this does is sets playerName to OykkoIsBack, then it gets the humanoid of the player with playerName and sets their jump power to 100.

Upvotes: 1

Buzzyy
Buzzyy

Reputation: 121

I’m quite new at scripting too, so I might be wrong but here’s what I think the mistake is:

First of all you put

Players.(playername).Character.Humanoid etc.

I think ‘playername’ shouldn’t have brackets?

Secondly, you just set the jumpPower to 100?? Try replacing the 100 with a variable, so after the = try writing the variable name.

I think this because the error is saying there was a bracket where it expected something else (from what I know) so I think it’s just the playername brackets.

Upvotes: 0

Related Questions