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

Trying to make a object material changer, works locally but not FE ???

Asked by 4 years ago

So I'm trying to make a material changer, so if I click on my left mouse button, it will change the material, it can work on localscript but CAN'T work when I try to covert it too FE compatible

here is if it's not FE :

local mouse = game:GetService("Players").LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    if mouse.Target.Name ~= "Baseplate" and not mouse.Target:IsA("Model") then
         mouse.Target.Material = Enum.Material.ForceField
    end
end)

so when I tried to convert it to FE compatible it doesn't give any error, and it won't work (even I tried to use ObjectValue)

FE Compatible script: (using RemoteEvents):

LocalScript

local mouse = game:GetService("Players").LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    script.SelectedObject.Value = mouse.Target
    game.ReplicatedStorage.BlockChange:FireServer(script.SelectedObject)
end)

Server script:

local objval = game.StarterPack.LocalBlockHandler.SelectedObject
local re = game.ReplicatedStorage.BlockChange

re.OnServerEvent:Connect(function(obj)
    if obj.Name ~= "Baseplate" and not obj:IsA("Model") then
        obj.Material = Enum.Material.ForceField
    end
end)

I get this error when using the FE compatible: https://imgur.com/a/M9OW8L0

1 answer

Log in to vote
0
Answered by
DogeIXX 172
4 years ago
Edited 4 years ago

When a Local Player fires the Server, the Player Object will be sent first.

Just change

re.OnServerEvent:Connect(function(obj)

to

re.OnServerEvent:Connect(function(plr, obj)

You don't have to use plr, but index it so you can use obj.

0
That seems to fix it, I fixed the rest also, thanks! RadiatedExodus 41 — 4y
0
Nice to hear that :) DogeIXX 172 — 4y
Ad

Answer this question