I am trying to give a sword (created in the script) to the player when they join but nothing happens and I am not getting any errors.
Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SwordClass = require(ReplicatedStorage:WaitForChild("SwordClass"))
local Swords = ReplicatedStorage:WaitForChild("Swords")
local testSword = SwordClass.new(Swords.BasicSword, "TestSword", 20, .2, .5, Swords.BasicSword.Animations:GetChildren())
game.Players.PlayerAdded:Connect(function(player)
testSword:GiveToPlayer(player)
end)
Module script
local ServerStorage = game:GetService("ServerStorage")
local Sword = {}
Sword.__index = Sword
function Sword.new(_model, _swordName, _damage, _attackLen, _cooldown, _animObjects)
local self = setmetatable({}, Sword)
self.damage = _damage
self.attackLen = _attackLen
self.cooldown = _cooldown
self.animations = _animObjects
-- Create sword tool
self.sword = Instance.new("Tool")
self.sword.Name = _swordName
self.sword.Parent = ServerStorage
-- Add clone of sword model to sword and parent handle to sword
local model = _model:Clone()
model.Parent = self.sword
model.Handle.Parent = self.sword
return self
end
function Sword:GiveToPlayer(player)
if player then
local clone = self.sword:Clone()
clone.Parent = player:WaitForChild("Backpack")
end
end
return Sword
