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

Calling an Event not working in Server?

I don't really see the issue with this, I've also tried disabling/enabling FilteringEnabled but that has no effect.

I have a LocalScript in StarterPlayerScripts, this is the script:

repeat wait() until game.Players.LocalPlayer
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button1Event = ReplicatedStorage:WaitForChild("Button1Event")

Mouse.KeyDown:connect(function(key)
	if key == "e" then
		Button1Event:FireServer()
		print("Fired")
	end
end)

It calls an event once the player press 'e' that works fine in studio as it prints "Fired" successfully but it will not call it in a server, does anyone know why?

1 comment

0

it might now work in server because it is stuck waiting on a child

1 answer

Try using a different code

local player = game.Players.LocalPlayer
repeat wait() until player.Character

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button1Event = ReplicatedStorage:WaitForChild("Button1Event")


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

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

2 comments

0

Nope doesn't work.

0

The code you've given me works fine in studio, but not in server, plus you don't need the bracket on the last end.

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