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

Why isn't the part detecting that it's being touched?

Asked by 6 years ago

So this is the server script,


local AmbientChanger = workspace.AmbientChanger debounce = false AmbientChanger.Touched:Connect(function(hit) print("Touched!") if not debounce and hit.Parent:FindFirstChild("Humanoid") then debounce = true workspace.RemoteEvents.AmbientChangerEvent:FireClient() end debounce = false end)

while this is the local script, which is in the RemoteEvent

script.Parent.OnClientEvent:Connect(function()
    print("Recieved!")
if game.Lighting.FogEnd == 100000 then

        for i = -1000, 100000, 500 do
        game.Lighting.FogEnd = i
        game.Lighting.FogColor = Color3.new(255, 255, 255)
        end

    else

        for i = 1000, 500, 100000 do
        game.Lighting.FogEnd = i

        end

    end

    end)

It doesn't even seem to detect that the brick is getting touched though, and I can't figure out why. FilteringEnabled is on.

0
the for loop on lines 12 through 15 doesn't work and the increment(100000) is greater than the absolute value of 500-1000 theking48989987 2147 — 6y

1 answer

Log in to vote
0
Answered by
Lugical 425 Moderation Voter
6 years ago
Edited 6 years ago

On line 9, in your first script, you are firing the remote event to a client. however, u didnt pass any valid arguments, so no client receives it. As the touch function would fetch the character, which is on the server, the remote event wouldn't be needed. Instead to do this:

--In StarterPlayerScripts
local debounce  = false


workspace.AmbientChanger.Touched:Connect(function(hit)
if debounce == false then debounce = true
if hit.Parent == game.Players.LocalPlayer.Character then
if game.Lighting.FogEnd == 100000 then --Make sure other events wouldn't change this prior!

        for i = -1000, 100000, 500 do
        game.Lighting.FogEnd = i
        game.Lighting.FogColor = Color3.fromRGB(255, 255, 255) --RGB, not New, is out of 255
        end

    else

        for i = 1000, 500, 100000 do --Change the third argument? Would give off an error.
        game.Lighting.FogEnd = i

        end
end
    end
end
debounce = false
    end)

Now, let me explain this, as you're trying to change the lighting on the client, and you need to know if that same client touches the part, it should all be done on a local script, eliminating the need of a local script. Rather, you should place the touched function in the same script. As well as checking if there is a humanoid, I would also check if on of the parts on the client's characters set it off. If so, it'll continue on with the rest of your code.

All in all, if you need to change stuff on the client with :Touched events, just combine them in a localscript, while adding some precautions so it'll work.

Hope this helps!

0
also color3.new() is is supposed to have values between 0 and 1, if you want values between 0 and 255, use color3.fromrgb() theking48989987 2147 — 6y
0
I edited it. Thanks for telling me another plausible error. Lugical 425 — 6y
0
It worked, thanks a lot to both of you! iAduriteX 34 — 6y
Ad

Answer this question