-- CLIENT SCRIPT --
--// SERVICES \\--
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// VARIABLES \\--
local remoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local digEvent = remoteEvents:WaitForChild("DigEvent")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F and not gameProcessedEvent then
digEvent:FireServer()
end
end)
-- MODULE SCRIPT (SERVER) --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = ReplicatedStorage.RemoteEvents
local digEvent = remoteEvents.DigEvent
local Digsite = {}
Digsite.__index = Digsite
function Digsite.new(tycoon, instance)
local self = setmetatable({}, Digsite)
self.Tycoon = tycoon
self.Instance = instance
self.Owner = tycoon.Owner
return self
end
function Digsite:Init()
self:ListenForDig()
end
function Digsite:ListenForDig()
digEvent.OnServerEvent:Connect(function(player)
if self.Owner == player then
print("This is the tycoon owner")
end
end)
end
return Digsite
I’m currently using OOP and I’m not sure how I can listen for input from the client properly.
How the system works so far is the player steps on a pad and another script creates the object and calls Digsite:Init()
externally.
When Digsite:Init()
is called and the player presses F once it prints "This is the tycoon owner"
once.
However, if the player presses F repeatedly before stepping on the pad, it prints "This is the tycoon owner"
however many times the player had pressed F previously.
What am I doing wrong?
Any help is appreciated.