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

Changing Properties w/ a variable using FE?

Hi, I'm having a problem w/ changing properties of objects using FE. Nothing is coming up when I try this on the output, however here's my script:

--In Local Script
local plyr = game.Players.LocalPlayer
local char = plyr.Character
local human = char:WaitForChild("Humanoid")
local mouse = game.Players.LocalPlayer:GetMouse()
local enabled = true
local running = false

mouse.KeyDown:connect(function (key)
key = string.lower(key)
if (key) == "r" and enabled == true then
enabled = false

if running == true then
running = false
game.Workspace.Scripts.ChangeObject:FireServer(human.WalkSpeed,30)

elseif running == false then
running = true
game.Workspace.Scripts.ChangeObject:FireServer(human.WalkSpeed,18)

end
wait(2)
enabled = true
end
end)
-- In Server Script
function ChangeObject(player,property,newproperty)
property = newproperty
end

script.ChangeObject.OnServerEvent:connect(ChangeObject)

Like I said, nothing shows up on the output when I do this, and I have no idea what's going wrong.

1 comment

0

Try printing 'property' first in the ChangeObject function.

1 answer

When you pass is a property, you do not pass in a reference to the property of that object but rather the value that the property held. You'll need to pass the actual object as well as the name of the property and the value it will hold as arguments.

Example: Change Part's BrickColor to a random color with a RemoteEvent

LocalScript

local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local part = game.Workspace.Part

RemoteEvent:FireServer(part, "BrickColor", BrickColor.Random())

ServerScript

local RemoteEvent = Instance.new("ReplicatedEvent", game.ReplicatedStorage)

local function ChangeObject(player, object, property, value)
	object[property] = value
end

RemoteEvent.OnServerEvent:connect(function(ChangeObject)

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