Hello! So I am currently trying to make a meme gun and I’m attempting to do so using RemoteEvents
, and my experience with them is not that great.
I keep getting this error: attempt to index nil with 'FireServer'
whenever my tool is activated.
Client:
local tool = script.Parent
local RemoteEvent = tool:FindFirstChildOfClass("RemoteEvent")
tool.Activated:Connect(function()
RemoteEvent:FireServer()
end)
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Memes = ReplicatedStorage.Memes
local tool = script.Parent
local RemoteEvent = tool:FindFirstChild("RemoteEvent")
local Handle = tool:FindFirstChild("Handle")
RemoteEvent.OnServerEvent:Connect(function(Player)
local RandomMeme = Memes[math.random(1, #Memes)]:Clone()
local function FireMeme()
RandomMeme.Anchored = true
RandomMeme.Position = tool.Handle.Position + Vector3.new(0, 0, -5)
RandomMeme.Parent = workspace
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Velocity = tool.Handle.CFrame.LookVector * 50
BodyVelocity.Parent = RandomMeme
task.wait(5)
RandomMeme:Destroy()
end
end)
If you think you know what went wrong, please let me know! Thank you and have a wonderful day!