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

How do I fix this on button click issue that I'm having? wasd

I'm trying to make the next outline remover & for some reason it doesn't work and without the camera & terrain check it would error and I'm trying to make this localscript from game.StarterGui.ScreenGui.Frame to ignore these 2 and with it, it wont error but do nothing. Any help?

local btn1 = script.Parent.TextButton
local btn2 = script.Parent.TextButton2

btn1.MouseButton1Click:Connect(function()
	for i, v in pairs(workspace:GetChildren()) do
		if workspace:FindFirstChild("Camera") or workspace:FindFirstChild("Terrain") then
			return
		end

		if v:IsA("Model") then
			for j, w in pairs(v:IsA("Model"):GetChildren()) do
				w.TopSurface = Enum.SurfaceType.Smooth
				w.BottomSurface = Enum.SurfaceType.Smooth
			end
		end
		
		v.TopSurface = Enum.SurfaceType.Smooth
		v.BottomSurface = Enum.SurfaceType.Smooth
	end
end)

4 comments

0

Also, I did put the "wasd" there to my title so my issue can get accepted because I can't explain the title more.

0

Didn't thought about that, great strategy

0

Wait so you want to make the TopSurface and BottomSurface to Smooth, and thats its?

0

for every part in workspace, yes.

1 answer

✓ Accepted answer

You are trying to set the surface of part INSIDE the client script

Please note that the client world doesn't replicate to other client world but only the server world will replicate the change to the client world. Unless you're trying to remove the outline of part surface ONLY in the client but the following code will utilize RemoteEvent.

RemoteEvent is a special part that serves as a communication tool for clients and servers. It's like how software communicates with hardware by using kernel code but much simpler. Functions are different for a different type of script (LocalScript and ServerScript): See Roblox article for more (https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events)

I also add a check if the part is actually part and not others (stringValue, script, etc.) because you want all parts in the workspace to be set.

==== CODE ====

LocalScript

local btn1 = script.Parent.TextButton
local btn2 = script.Parent.TextButton2 -- unused
local remote = game.ReplicatedStorage.RemoteEvent -- Get the remoteEvent

btn1.MouseButton1Click:Connect(function()
   Remote:FireServer() -- Fire remoteEvent from client to server
end)

ServerScript

local remote = game.ReplicatedStorage.RemoteEvent -- Get the remoteEvent

remote.OnServerEvent:Connect(function() -- Listen to remoteEvent if client fired remoteEvent
   for i, v in pairs(workspace:GetChildren()) do
        if workspace:FindFirstChild("Camera") or workspace:FindFirstChild("Terrain") then
            return
        end

        if v:IsA("Model") then -- Part checked is a model
            for j, w in pairs(v:GetChildren()) do -- 2nd Loop -- v:IsA():GetChildren() is unnecessary complication. Removed IsA().
                if w:IsA("Part") then -- Part checked is actually part
                   w.TopSurface = Enum.SurfaceType.Smooth
                   w.BottomSurface = Enum.SurfaceType.Smooth
                end
            end
        end
        if v:IsA("Part") then -- Part checked is actually part
           v.TopSurface = Enum.SurfaceType.Smooth
           v.BottomSurface = Enum.SurfaceType.Smooth 
        end
    end
end)

NOTE: Allowing anyone to remove the outline from every part of the workspace is extremely dangerous and a user ID check is recommended but the code shown above is not including a user ID check.

If you're trying to remove the outline ONLY from the user perspective then this answer will not be helpful. But if you did want to remove the outline in every player's perspective then in the future, you probably want to research about RemoteEvent and RemoteFunction because these things are important for the game.

Happy Scripting!

2 comments

0

If you found this answer helpful, either directly or indirectly and the answer is working then you can accept this answer and help others who may have the same problem.

0

I forgot to mention the word "plugin", not a game & it's currently a prototype GUI, just saying. TextButton2 is unused because I haven't coded it yet.

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