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

Unable to cast value to Object?

im trying to make a filtering enabled face changer gui.

I have these 2 scripts, ServerScriptService and the Server Script in the gui

****the error is on line 7 in the server script in the gui

ServerScriptService:

game.ReplicatedStorage:WaitForChild('Faces').OnServerEvent:connect(function(player,realface)
	print("asd")
	player:WaitForChild('Character').Head.face.Texture = realface
end)

Server script in the gui:

    local f = script.Parent:GetChildren()
	for i = 1,#f do
		local face = f[i]
		if face.Name == "Face" or face.Name == "Face1" or face.Name == "Face2" then
			face.MouseButton1Down:connect(function(player)
				local realface = face.Image
				game.ReplicatedStorage:WaitForChild('Faces'):FireClient(realface)
			end)
		end
	end

2 comments

0

if your game have filtering enabled you should use a RemoteEvent

0

Im using a remote event.

1 answer

Well, you can't fire a RemoteEvent with a server using FireClient Change the serverscript in your GUI to a LocalScript and put this code.

local f = script.Parent:GetChildren()
for i = 1,#f do
    local face = f[i]
    if face.Name == "Face" or face.Name == "Face1" or face.Name == "Face2" then
	if not face:IsA("LocalScript") then
        face.MouseButton1Down:connect(function(player)
            local realface = face.Image
            game.ReplicatedStorage:WaitForChild('Faces'):FireServer(realface)--Firing it correctly
        end)
	end
    end
end

3 comments

0

Now it gives out an error saying "MouseButton1Click is not a valid member of LocalScript"

0

There I edited the script

0

Thanks!

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