Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Why does my revolver's scripts break when the revolver is cloned or moved?

So I have a project of re-creating old Murder Mystery by Nikilis, and I ran into a strange error that when the game is picking roles, the revolver doesn't work after it is cloned/moved, however it works perfectly fine if it's on StarterPack, any help or potential solutions?

I already tried switching from ReplicatedStorage to ServerStorage, already tried disabling and re-enabling the localscript through script and manually but it's still broken. And I'm also using the same method to clone the knife but the knife doesn't break.

Complete Explorer: https://prnt.sc/s3kocp (The only thing that matters in this picture is the RoundSystem script and the Weapons)

Script: (The clone part is at line 79)

--//Services
local serverScriptService = game:GetService("ServerScriptService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
local debris = game:GetService("Debris")

--//Variables
local roundInformation = serverScriptService:WaitForChild("RoundInformation")
local serverInformation = serverScriptService:WaitForChild("ServerInformation")

local spawnPoint = workspace:WaitForChild("Spawn")
local teleportPart = spawnPoint:WaitForChild("TeleportPart")

local timeCounter = spawnPoint:WaitForChild("TimeCounter")
local timeLeftLabelPart = timeCounter:WaitForChild("TimeLeftLabel")
local timeLeftGUI = timeLeftLabelPart:WaitForChild("TimeLeftGUI")
local timeLeftLabel = timeLeftGUI:WaitForChild("TimeLeftLabel")

local roleGUI = script:WaitForChild("RoleGUI")

local maps = workspace:WaitForChild("Maps")

local weapons = serverStorage:WaitForChild("Weapons")
local knife = weapons:WaitForChild("Knife")
local revolver = weapons:WaitForChild("Revolver")

local names = {"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November", "Oscar", 
"Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "Xray", "Yankee", "Zulu"}

--//Functions
local function checkPlayers()
	local function startRound()
		local murdererPicked = false
		local sheriffPicked = false
		
		local selectedMap = maps:GetChildren()[math.random(1, #maps:GetChildren())]
		local spawnpoints = selectedMap:WaitForChild("Spawnpoints")
		
		for i, v in pairs(players:GetPlayers()) do
			local backpack = v:WaitForChild("Backpack")
			local playerGUI = v:WaitForChild("PlayerGui")
			local char = v.Character
			
			local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
			local torso = char:WaitForChild("Torso")
			local head = char:WaitForChild("Head")
			
			local nameGUI = head:WaitForChild("NameGUI")
			local nameLabel = nameGUI:WaitForChild("NameLabel")
			
			humanoidRootPart.CFrame = spawnpoints:GetChildren()[math.random(1, #spawnpoints:GetChildren())].CFrame
			
			torso.Color = Color3.new(math.random(1, 255), math.random(1, 255), math.random(1, 255))
			nameLabel.TextColor3 = torso.Color
			nameLabel.Text = names[math.random(1, #names)]
			
			local isIngame = Instance.new("StringValue", char)
			isIngame.Name = ("Ingame")
			
			local newRoleGUI = roleGUI:Clone()
			local roleLabel = newRoleGUI:WaitForChild("RoleLabel")
			
			newRoleGUI.Parent = playerGUI
			
			debris:AddItem(newRoleGUI, 5)
			
			require(roundInformation).AddAlivePlayers()
			
			if not murdererPicked then
				local newKnife = knife:Clone()
				newKnife.Parent = backpack
				
				murdererPicked = true
				
				roleLabel.Text = ("You are the Murderer. Kill all other players to win")
				roleLabel.TextColor3 = Color3.new(255, 0, 0)
				
			elseif murdererPicked and not sheriffPicked then
				local newRevolver = revolver:Clone()
				newRevolver.Parent = backpack
				
				sheriffPicked = true
				
				roleLabel.Text = ("You are the Sheriff. Kill the Murderer with your gun to win. You will die upon killing an innocent player.")
				roleLabel.TextColor3 = Color3.new(0, 0, 255)
				
			elseif murdererPicked and sheriffPicked then
				roleLabel.Text = ("You are an Innocent. Avoid the Murderer!")
				roleLabel.TextColor3 = Color3.new(0, 255, 0)
				
			end
		end
		
		require(roundInformation).StartRound()
		
		local function endRound(endMessage)
			for i, v in pairs(players:GetPlayers()) do
				local backpack = v:WaitForChild("Backpack")
				local char = v.Character
				local humanoidRootPart = char:FindFirstChild("HumanoidRootPart")
				local head = char:FindFirstChild("Head")
				
				if humanoidRootPart and head then
					humanoidRootPart.CFrame = teleportPart.CFrame
					
					local nameGUI = head:WaitForChild("NameGUI")
					local nameLabel = nameGUI:WaitForChild("NameLabel")
					
					nameLabel.Text = v.Name
					
					for i, t in pairs(char:GetChildren()) do
						if t:IsA("Tool") then
							t.Parent = backpack
						end
					end
					
					for i, t2 in pairs(backpack:GetChildren()) do
						t2:Destroy()
					end
					
				else
					v:LoadCharacter()
					
					local char = v.Character
					
					local head = char:WaitForChild("Head")
					local nameGUI = head:WaitForChild("NameGUI")
					local nameLabel = nameGUI:WaitForChild("NameLabel")
					
					nameLabel.Text = v.Name
				end
			end
			
			local endingMessage = Instance.new("Message", workspace)
			endingMessage.Text = endMessage
			
			debris:AddItem(endingMessage, 5)
			
			require(roundInformation).StopRound()
			
			checkPlayers()
		end
		
		while wait(1) do
			if require(roundInformation).PlayersAlive > 1 and require(roundInformation).TimeLeft > 0 then
				require(roundInformation).SubtractTime(1)
				
				timeLeftLabel.Text = tostring(require(roundInformation).TimeLeft)
				
			elseif require(roundInformation).PlayersAlive == 1 and require(roundInformation).MurdererKilled == false then
				endRound("The Innocents have been eliminated! The Murderer has won.")
				
				break
				
			elseif require(roundInformation).PlayersAlive >= 1 and require(roundInformation).MurdererKilled == true then
				endRound("The Murderer has been killed! The Innocents win.")
				
				break
				
			elseif require(roundInformation).MurdererKilled == false and require(roundInformation).TimeLeft <= 0 then
				endRound("Times up! The Murderer did not kill his victims in time. The Innocents win!")
				
				break
			end
		end
	end
	
	while wait(15) do
		if require(serverInformation).PlayerCount > 1 then
			startRound()
			
			break
			
		else
			local notEnoughPlayersMessage = Instance.new("Message", workspace)
			notEnoughPlayersMessage.Text = ("Not enough players to start a match!")
			
			debris:AddItem(notEnoughPlayersMessage, 2.5)
		end
	end
end

--//Callers
checkPlayers()

3 comments

0

Can you provide the script, also the exact error happend to me, I managed to fix it by waiting around 5 seconds for the gun to load, so put a loading screen etc

0

yeah please post the script it sounds like there are specific parents in the script that are messing up when you move it

0

Done

1 answer

Aight, I just found out my mistake and that was that in the revolver localscript, when doing a variable for the player's character, I used .CharacterAdded:Wait() instead of simply .Character, I changed it and now it works again.

/¯(?)_/¯

This discussion is preserved as it was. New answers, comments, and votes are closed.