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

Changing Properties w/ a variable using FE?

Asked by 8 years ago

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.

0
Try printing 'property' first in the ChangeObject function. Pyrondon 2089 — 8y

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
Ad

Answer this question