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

RemoteEvent's cannot be Listened for?

Asked by
iFlusters 355 Moderation Voter
8 years ago

This is hard to explain, but I'l try my best.

FireServer()

So basically I have a RemoveEvent which is fired if a player presses e here's the LocalScript which is located in StarterPlayerScripts:

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then
        Button1Event:FireServer()
        print("Fired")
    end
end

Then this script receives it, which calls another event as I plan to add a Magnitude to the object rather than pressing e whenever you want and getting chest items as well as because I am having multiple chests this will mean that it will mess up and call about 10 times.

Listener Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button1Event = ReplicatedStorage:WaitForChild("Button1Event")
local ChestOpenEvent = script.Parent:WaitForChild("ChestOpenEvent")

function OpenChest(Player)
    if not Player then
        return;
    end

    if not script.Parent:WaitForChild("ChestOpenEvent") then
        script.Parent:Destroy()
    return;
end
    ChestOpenEvent:FireServer()
end

game.ReplicatedStorage.Button1Event.OnServerEvent:connect(OpenChest)

Output

Everything works fine in studio, but as always, it doesn't work in server. This is the only output I'm getting, however that is for the ChestOpenEvent:FireServer() part.

19:39:11.476 - FireServer can only be called from the client
19:39:11.476 - Script 'Workspace.Chest.Sensor.Script', Line 14
19:39:11.477 - Stack End

Conclusion

In conclusion, there's a LocalScriptin StarterPlayerScriptswhich waits for the key e to be pressed, once it's pressed it will fire a RemoveEventwhich is in ReplicatedStorage. I then have another script inside of a part listening for that event to be fired, which will then call another event, the reason I have this other event is (because I plan to add a Magnitude to the chest in where a player can/can't open a chest as many chests will exist) which opens the chest and gives the player their items.

0
Use a BindableEvent for the server to server part. You cant use FireServer from a script. hence the error saying exactly that. iaz3 190 — 8y
0
Alright, but the listener won't even detect when a player presses 'e' however it will fire it correctly. iFlusters 355 — 8y
0
Who downvoted this question and why? :/ iFlusters 355 — 8y

Answer this question