So, I’m trying to make tools that fire projectiles, and I also have a time bomb tool. All of them are in ServerStorage and have a prefab for the projectile/weapon body that gets cloned and set to the CFrame.
I’m gonna use just the time bomb for this post since whatever solution there may be will probably fix the others as well.
But the issue I have is only when the tool is cloned out of ServerStorage and into the player’s backpack. This is done on the server via ModuleScript for the round. The time bomb and other tools still clone the prefab for it, but it does NOT change the CFrame or position accordingly. The rest of the code works, it’s just the CFrame that isn’t being set. The tools work 100% perfectly fine when cloned by hand in test mode or if it was in StarterGear.
And also, all of the code for the time bomb was written myself. That is at the bottom of the post.
I’ve looked through old posts on the DevForum, but not of them were similar to my issue or their solution had deprecated solutions that would not work.
I’ve also tried disabling the script in the tool and enabling it when it’s cloned into the player’s backpack.
Screenshots of the game setup:
Here’s the code:
Specific lines in the round module:
local toolPack = replicatedStorage.MainGame.Tools.WeaponPacks:FindFirstChild(plr.EquippedPack.Value)
unpackageTools(plr, toolPack)
The entire round script:
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local serverStorage = game:GetService("ServerStorage")
local soundService = game:GetService("SoundService")
local marketPlaceService = game:GetService("MarketplaceService")
local musicFolder = soundService:WaitForChild("GameMusic")
local otherSounds = soundService:WaitForChild("OtherSounds")
local maps = serverStorage:WaitForChild("MainGame"):WaitForChild("Maps")
local mainGame = replicatedStorage:WaitForChild("MainGame")
local remotes = mainGame:WaitForChild("Remotes")
local gameValues = mainGame:WaitForChild("GameValues")
local status = gameValues:WaitForChild("Status")
local cashReward = 75
local expReward = 50
local function toMS(s)
return ("%02i:%02i"):format(s/60%60, s%60)
end
local function unpackageTools(player, pack)
local clone = pack:Clone()
clone.Parent = player
for _, tool in pairs(clone:GetChildren()) do
tool.Parent = player.Backpack
for __, Script in pairs(tool:GetDescendants()) do
if Script:IsA("Script") and Script.Enabled == false then
Script.Enabled = true
end
end
end
clone:Destroy()
end
local round = {}
function round.Waiting(numberOfPlayers, minimumPlayers)
status.Value = minimumPlayers.." ready players are required to start ("..numberOfPlayers.."/"..minimumPlayers.." players)"
end
function round.Intermission(intermissionTime)
for i=intermissionTime,0,-1 do
status.Value = "Intermission ("..i..")"
task.wait(1)
end
end
function round.StartRound(gameLength)
status.Value = ""
local plrs = {}
for i, player in pairs(Players:GetPlayers()) do
table.insert(plrs,player)
end
task.wait(2)
local availableSongs = soundService:WaitForChild("GameMusic"):GetChildren()
local chosenSong = availableSongs[math.random(1,#availableSongs)]
local availableMaps = maps:GetChildren()
local chosenMap = availableMaps[math.random(1,#availableMaps)]
status.Value = chosenMap.Name.." was selected"
task.wait(2)
local newMap = chosenMap:Clone()
newMap.Name = chosenMap.Name
newMap.Parent = workspace
local spawnPoints = newMap:FindFirstChild("SpawnPoints")
if not spawnPoints then
warn("Critical Error: There are no spawn points in "..chosenMap.Name.."!")
end
local availableSpawns = spawnPoints:GetChildren()
for i=5,0,-1 do
status.Value = "Game will start in "..i
task.wait(1)
end
remotes:WaitForChild("RoundMusic"):FireAllClients(chosenSong, "On")
for i, plr in pairs(plrs) do
if plr then
local character = plr.Character
coroutine.resume(coroutine.create(function()
if not character then
plr:LoadCharacter()
wait(0.1)
character = plr.Character
end
wait(1.2)
character.HumanoidRootPart.Position = availableSpawns[1].Position + Vector3.new(0, 8, 0)
local hitbox = serverStorage.MainGame.Prefabs.Hitbox:Clone()
hitbox.Parent = character
hitbox.CFrame = character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Parent = hitbox
weld.Part0 = hitbox
weld.Part1 = character.HumanoidRootPart
local toolPack = replicatedStorage.MainGame.Tools.WeaponPacks:FindFirstChild(plr.EquippedPack.Value)
unpackageTools(plr, toolPack)
local gameTag = Instance.new("BoolValue")
gameTag.Name = "GameTag"
gameTag.Parent = character
end));
else
if not plr then
table.remove(plrs,i)
end
end
end
wait(1.3)
for i=gameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
local character = player.Character
if not character then
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
--Still in game
continue
else
table.remove(plrs,x)
player.leaderstats.Cash.Value += 5
player.leaderstats.Level.CurrentExp.Value += 10
end
end
else
table.remove(plrs,x)
end
end
status.Value = "Time: "..toMS(i).." remaining"
if #plrs == 1 then
status.Value = "Cleaning Up: Say congrats to the survivor!"
task.wait(4)
status.Value = ""
plrs[#plrs].leaderstats.Cash.Value += cashReward
plrs[#plrs].leaderstats.Level.CurrentExp.Value += expReward
plrs[#plrs].leaderstats.Wins.Value += 1
break
elseif #plrs == 0 then
status.Value = "Restarting: No one survived."
break
elseif i == 0 then
status.Value = "Restarting: Time has run out."
break
end
wait(1)
end
wait(1.5)
for i, player in pairs(Players:GetPlayers()) do
local character = player.Character
if not character then
continue
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
for _, tool in pairs(player.Backpack:GetChildren()) do
if tool:IsA("Tool") then
tool:Destroy()
end
end
for _, tool in pairs(character:GetChildren()) do
if tool:IsA("Tool") then
tool:Destroy()
end
end
end
player:LoadCharacter()
end
table.clear(plrs)
chosenSong:Stop()
soundService.OtherSounds.Birds:Play()
status.Value = "Cleaning up map..."
wait(3)
newMap:Destroy()
wait(7)
end
return round
Server code running the module:
-- >>: Round
coroutine.resume(coroutine.create(function()
while true do
repeat task.wait(1) round.Waiting(#Players:GetPlayers(), minimumPlayers) until #Players:GetPlayers() >= minimumPlayers
round.Intermission(intermissionTime)
round.StartRound(gameLength)
task.wait(3)
end
end))
Time bomb script (tool):
local Players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")
local prefabs = serverStorage:WaitForChild("MainGame"):WaitForChild("Prefabs")
local tool = script.Parent
local event = tool:WaitForChild("Event")
local cooldown = false
local cooldownTime = 15
local character
tool.Equipped:Connect(function()
character = tool.Parent
end)
tool.Activated:Connect(function()
if not cooldown then
if character then
local bombClone = prefabs:FindFirstChild(tool.Name):Clone()
bombClone.Parent = workspace
bombClone.PrimaryPart.CFrame = tool:WaitForChild("Handle").CFrame
if bombClone:FindFirstChild("WeaponScript") and bombClone:FindFirstChild("WeaponScript"):IsA("Script") then
bombClone:FindFirstChild("WeaponScript").Enabled = true
end
cooldown = true
event:FireClient(Players:GetPlayerFromCharacter(character), "Reloading")
task.wait(cooldownTime)
event:FireClient(Players:GetPlayerFromCharacter(character), "Reloaded")
cooldown = false
end
end
end)
Time bomb script (prefab):
local bomb = script.Parent
local tickSound = bomb:WaitForChild("Tick")
local explosionSound = bomb:WaitForChild("Explosion")
local updateInterval = 0.8
local function updateTime()
tickSound:Play()
updateInterval *= 0.9
end
local function blowUp()
local explosion = Instance.new("Explosion")
explosion.Parent = workspace
explosion.BlastRadius = 20
explosion.BlastPressure = 1000000
explosion.Position = bomb.Base.Position
bomb.String.Transparency = 1
bomb.Base.Transparency = 1
bomb.Top.Transparency = 1
explosionSound:Play()
end
while updateInterval > 0.1 do
task.wait(updateInterval)
updateTime()
end
blowUp()
task.wait(3)
bomb:Destroy()
Any help is greatly appreciated! Thank you!
Best regards,
Amora.