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

[Solved]Why is this remote function not working correctly?

Asked by 5 years ago
Edited 5 years ago

I have an event that fires when someone touches a box. After the event is fired I reward them with a prize and destroy the box. The problem is that in the server the box disappears after a whole second. In order to fix that issue I created a remote function that would fade the box out on the client side. Here is the script:

print("got here") -- this prints
remoteFunction:InvokeClient(plr, box)
box:Destroy()

and here is the local script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local eventsFunctions = replicatedStorage:WaitForChild("Events/Functions")
local neededFunction = eventsFunctions:FindFirstChild("RemoteFunction")

local success, message = pcall(function()

    if neededFunction then

        neededFunction.OnServerInvoke = function(plr, box)
            print("fired") -- this does not print
            if box:IsA("BasePart") then

                for i = 0.1, 1 do
                    wait(1)
                    box.Transparency = i
                end

            end

        end

    end

end)
if success then
    print("Happy")--this prints
end

A few notes: The local script is placed inside of StarterPlayerScripts. There is only one function inside of Events/Functions. The box does not fade out. The server script works fine. Thanks!

0
If you have any comments on better methods feel free to post them. User#21908 42 — 5y
0
I just realized that the for loop would not work anyway. However, the remote function problem still needs addressed. User#21908 42 — 5y
1
Thanks to incapaz for the solution. OnClientInvoke was needed. User#21908 42 — 5y

Answer this question