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

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

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

✓ Accepted answer

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.

2 comments

0

That seems to fix it, I fixed the rest also, thanks!

0

Nice to hear that :)

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