- What do you want to achieve? Keep it simple and clear!
So I have been currently working on fps system that uses modules to change weapons. I have the clinet side down, but I need to send the current module information to the server script so I can change the weapon or fire a bullet.
- What is the issue? Include screenshots / videos if possible!
I have a script done for the server event, however my server script code is not picking up the veriable form the client script to require the correct module. I will put this code down below as an example:
This is the client script
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local tweenservice = game:GetService("TweenService")
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera
local GunEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("GunEvent")
local framework = {
inventory = {
"ShanseiC44";
"RaptorL28";
"PowerDrill";
};
module = nil;
viewmodel = nil;
currentSlot = 1;
}
-- Weapon Framwork Function --
function Loadslot(Item)
local viewModelFolder = game.ReplicatedStorage.ViewModels
local moduleFolder = game.ReplicatedStorage.Modules
for i, v in pairs(camera:GetChildren()) do
if v:IsA("Model") then
v:Destroy()
end
end
if moduleFolder:FindFirstChild(Item) then
framework.module = require(moduleFolder:FindFirstChild(Item))
GunEvent:FireServer(Item)
if viewModelFolder:FindFirstChild(Item) then
framework.viewmodel = viewModelFolder:FindFirstChild(Item):Clone()
framework.viewmodel.Parent = camera
end
end
end
Loadslot(framework.inventory[1])
And this is the server script
local RunService = game:GetService("RunService")
local GunEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("GunEvent")
local remoteEvent = game.ReplicatedStorage.RemoteEvents:FindFirstChild("ShotEvents")
local Module = nil
GunEvent.OnServerEvent:Connect(function(item)
for i, v in pairs(game.ReplicatedStorage.Modules:GetChildren()) do
if v.Name == item then
Module = require(v)
print("Module is loaded")
else
print("Could not find module")
end
end
end)
When i run the game it can’t find the module so it comes back with “could n ot find module”
I have a feeling I am not using the veriables in the function properly so I cam reached out to all you lovely coders to ask if you can see if I’ve made a mistake or how to make this work.