Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it even possible to access an Instance's property via string?

Asked by 5 years ago

For an example, I want to set the Humanoid's WalkSpeed, I could just do this.

hum.WalkSpeed = 100

But what if, a player sends a string to the server and want the server to set a certain property for the player?

For an example:

local stringReceived = "WalkSpeed"

plrhum.stringReceived = 100

Still don't know how can I be able to do it. Or is it impossible?

0
Yes DinozCreates 1070 — 5y
1
It would be more helpful if you showed me how to do it. magicguy78942 238 — 5y
0
You didnt ask that, you asked if it was possible. It is. DinozCreates 1070 — 5y
0
It is. WideSteal321 773 — 5y
0
it is seith14 206 — 5y

2 answers

Log in to vote
1
Answered by
seith14 206 Moderation Voter
5 years ago
Edited 5 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

server script

local event = game.ReplicatedStorage.ChangeHum -- The Event

event.OnServerEvent:Connect(function(plr,property,num) -- the fired function that gave the property and number from localscript
    plr.Character.Humanoid[property]=num
end)

local script

local event = game.ReplicatedStorage.ChangeHum -- The Event

event:FireServer("WalkSpeed",1000) -- gives the property and number
0
you honestly don't even need the wait(1) on the Server Event, there's an automatic delay in using the remote event (albeit a short one) SerpentineKing 3885 — 5y
0
Oh my god I'm an idiot asdjasjdljasld magicguy78942 238 — 5y
Ad
Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Yes. obj.index is sugar for obj["index"]. However the former only works if it is a valid identifier. obj.+]^} is not a valid identifier. It must therefore be indexed with square brackets. obj["+]^}"].

plrhum[stringReceived] is how you would do it.

Answer this question