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

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

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?

5 comments

0

Yes

1

It would be more helpful if you showed me how to do it.

0

You didnt ask that, you asked if it was possible. It is.

0

It is.

0

it is

2 answers

✓ Accepted 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

2 comments

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)

0

Oh my god I'm an idiot asdjasjdljasld

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.

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