Why does my code absolutely ignore my code?

Hello roblox developers!
INTRODUCTON
I’m creating a game called “Streak Simulator” in which your kills are numbered to make you stronger.
PROBLEM
For the final phase, the ability is to kill people on a specific hitbox per second.
I have a part called “StreakPhase7Hitbox” and a folder called “UnaffectedItems” and I added this folder so that players can’t punch the hitbox part w/ the player. My code ABSOLUTELY ignores my clone code for the hitbox. When it runs, I get an error stating that the hitbox is not a valid member of the folder.

Code (Server Script):

game.ReplicatedStorage.StreakPhase7.OnServerEvent:Connect(function(plr, player)
	player.PlayerGui.PressEStreakPhase6:Destroy()
	player.PlayerGui.MobileStreak6:Destroy()
	local NewFolder = Instance.new("Folder")
	NewFolder.Parent = player.Character
	NewFolder.Name = "UnaffectedItems"
	local SP7H = game.ServerStorage.StreakPhase7Hitbox:Clone()  <- This it where it ignores the codes.
	SP7H.Parent = player.Character.UnaffectedItems  <- This it where it ignores the codes.
	SP7H.Safe.Value = player.Name  <- This it where it ignores the codes.
	player.PlayerGui.PressEStreakPhase7.Enabled = true
	player.PlayerGui.MobileStreak7.Enabled = true
	for i, v in pairs(player.Character:GetDescendants()) do
		if v.ClassName == "ParticleEmitter" or v.Name == "Powerful" then
			v:Destroy()
		end
	end
	local SP6 = player.Character.Head.StreakPhase6
	SP6:Destroy()
	local char = player.Character
	player.Values.StreakPhase6.Value = false
	player.Values.StreakPhase7.Value = true
	player.Values.AbleToPunch.Value = true
	player.Values.PowerAbility.Value += 2500
	player.Character.Animate:Destroy()
	game.ReplicatedStorage.AnimationFinal:Clone().Parent = player.Character
	player.Character.Humanoid.WalkSpeed = 25
	player.Values.Walkspeed.Value -= 60
	local DetailNoS = game.ReplicatedStorage.DetailPhase7Streak:Clone()
	DetailNoS.Parent = player.Character.HumanoidRootPart
	for i, v in pairs(DetailNoS:GetChildren()) do
		v.Parent = player.Character.HumanoidRootPart
		local newV = v:Clone()
		newV.Parent = player.Character.Head
		local newV2 = v:Clone()
		newV2.Parent = player.Character["Left Arm"]
		local newV3 = v:Clone()
		newV3.Parent = player.Character["Left Leg"]
		local newV4 = v:Clone()
		newV4.Parent = player.Character["Right Arm"]
		local newV5 = v:Clone()
		newV5.Parent = player.Character["Right Leg"]
		local newV6 = v:Clone()
		newV6.Parent = player.Character.Torso
	end
	DetailNoS:Destroy()
	wait(3)
	local SP7 = workspace.StreakPhase7:Clone()
	SP7.Parent = player.Character.Head
	SP7:Play()
	wait(18.83)
	game.Workspace.ValuesServer.FOVGui.Value = true
	local Transformation1 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation1.Parent = player.Character.HumanoidRootPart
	for i, v in pairs(Transformation1:GetChildren()) do
		v.Parent = player.Character.HumanoidRootPart
	end
	Transformation1:Destroy()
	local Transformation2 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation2.Parent = player.Character.Head
	for i, v in pairs(Transformation2:GetChildren()) do
		v.Parent = player.Character.Head
	end
	Transformation2:Destroy()
	local Transformation3 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation3.Parent = player.Character["Left Arm"]
	for i, v in pairs(Transformation3:GetChildren()) do
		v.Parent = player.Character["Left Arm"]
	end
	Transformation3:Destroy()
	local Transformation4 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation4.Parent = player.Character["Left Leg"]
	for i, v in pairs(Transformation4:GetChildren()) do
		v.Parent = player.Character["Left Leg"]
	end
	Transformation4:Destroy()
	local Transformation5 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation5.Parent = player.Character["Right Arm"]
	for i, v in pairs(Transformation5:GetChildren()) do
		v.Parent = player.Character["Right Arm"]
	end
	Transformation5:Destroy()
	local Transformation6 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation6.Parent = player.Character["Right Leg"]
	for i, v in pairs(Transformation6:GetChildren()) do
		v.Parent = player.Character["Right Leg"]
	end
	Transformation6:Destroy()
	local Transformation7 = game.ReplicatedStorage.TransformationCompleteShock:Clone()
	Transformation7.Parent = player.Character.Torso
	for i, v in pairs(Transformation7:GetChildren()) do
		v.Parent = player.Character.Torso
	end
	Transformation7:Destroy()
	workspace.ValuesServer.TransformPhase7StreakGui.Value = true
	game.ReplicatedStorage.FinalPhaseEffectShock:Fire(player)
	wait(2)
	workspace.ValuesServer.FOVGui.Value = false
	workspace.ValuesServer.TransformPhase7StreakGui.Value = false
end)

game.ReplicatedStorage.StreakPhase7Ability.OnServerEvent:Connect(function(plr, player)
	player.PlayerGui.AbilityGUI.Enabled = true
	player.Character:WaitForChild("UnaffectedItems").StreakPhase7Hitbox.ShockScript.Disabled = false  <- This it where it errors.
	player.PlayerGui.AbilityGUI.AbilityMain.AbilityCount.Text = "1"
	wait(1)
	player.PlayerGui.AbilityGUI.Enabled = false
	player.Character:WaitForChild("UnaffectedItems").StreakPhase7Hitbox.ShockScript.Disabled = true  <- This it where it errors.
end)

Can you please help me? Thanks.

2 Likes

Can you explain on where exactly your issue is?

By looking at it, you are using a RemoteEvent

  • Are you sure its inside ReplicatedStorage along with the Script?

  • Are you sure you are Firing the RemoteEvent with :FireServer()?

Not Sure why you have a second variable named player, can you explain that?

Remote event in replicated storage?

Shouldn’t that be in server script storage or workspace?

RemoteEvents are for client and server usage, so the ideal place is ReplicatedStorage

local SP7H = game.ServerStorage.StreakPhase7Hitbox:Clone()
SP7H.Parent = player.Character.UnaffectedItems
SP7H.Safe.Value = player.Name

Everything else other than these lines of code work.
Yes: It is in ServerScriptService
I am firing it with :FireServer
Proof:

local player = game.Players.LocalPlayer
player.leaderstats.Kills:GetPropertyChangedSignal("Value"):Connect(function()
	if player.Values.Streak.Value == true then
		if player.Values.StreakKills.Value >= 5 and player.Values.StreakPhase1.Value == false and player.Values.StreakPhase2.Value == false and player.Values.StreakPhase3.Value == false and player.Values.StreakPhase4.Value == false and player.Values.StreakPhase5.Value == false and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase1:FireServer(player)
		end

		if player.Values.StreakKills.Value >= 10 and player.Values.StreakPhase2.Value == false and player.Values.StreakPhase3.Value == false and player.Values.StreakPhase4.Value == false and player.Values.StreakPhase5.Value == false and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false and player.Values.StreakKills.Value then
			game.ReplicatedStorage.StreakPhase2:FireServer(player)
		end
		
		if player.Values.StreakKills.Value >= 25 and player.Values.StreakPhase3.Value == false and player.Values.StreakPhase4.Value == false and player.Values.StreakPhase5.Value == false and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase3:FireServer(player)
		end
		
		if player.Values.StreakKills.Value >= 50 and player.Values.StreakPhase4.Value == false and player.Values.StreakPhase5.Value == false and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase4:FireServer(player)
		end
		
		if player.Values.StreakKills.Value >= 75 and player.Values.StreakPhase5.Value == false and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase5:FireServer(player)
		end
		
		if player.Values.StreakKills.Value >= 100 and player.Values.StreakPhase6.Value == false and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase6:FireServer(player)
		end
		
		if player.Values.StreakKills.Value >= 250 and player.Values.StreakPhase7.Value == false then
			game.ReplicatedStorage.StreakPhase7:FireServer(player)
		end
	end
end)
--This script is a local script in StarterGui

Also i dont know why i have two player variables so dont judge me :smiley:

I may see the issue here. Based on the 1st line of code, I assume you are in a LocalScript. When you declar “SP7H”, you reference ServerStorage, but that is not accessible by the client. Correct me if I’m mistaken here.

Im not sure why you have a second Variable for the Player, the First Variable literally is the player

Your reply scares me, you don’t have random scripts in workspace too do you?

your wrong. im using a regular script in serverscriptservice

ill change it i guess…? i dont know why that bothers you because its irrelevant from what im asking for.

local RepStorage = game:GetService(“ReplicatedStorage”)

RepStorage:WaitForChild(“StreakPhase7”).OnServerEvent:Connect(function(plr, player)

Then “game.Players.LocalPlayer” won’t work, as that only works on the client.

all i had to really do was just really simple.
how naive i was. i really thought that adding a part to the character without even SETTING it’s position and welding it to the character would work.
it works now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.