Why won't these scripts work at all?

Hi, I’m having a lot of difficulty right now, trying to get these scripts to work. There’s no errors, but whatever I do doesn’t work. I’ve tried searching it up on youtube but found nothing.
What’s happening is, in the first script there’s a max people limit per this class. However, when I tested it with 4 people, everyone was that class. It is a script in ServerScriptService.

local Classes = {"Class-D", "Scientist", "Guard", "SCP"}
local Classdclass = game.ReplicatedStorage.Classdclass
local SCPClass = game.ReplicatedStorage.SCPClass
local ScientistClass = game.ReplicatedStorage.ScientistClass
local GuardClass = game.ReplicatedStorage.GuardClass
local MaxScp = 2
local SCPS = 0
local PlayerClass = ""
Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
	for i, player in pairs(Players:GetPlayers()) do
		PlayerClass = math.random(1, #Classes)
		print(PlayerClass)
		if PlayerClass == 4 and SCPS < MaxScp then
			SCPClass:Fire()
			SCPS = SCPS - 1
		elseif SCPS > MaxScp then
			print('max scps')
		end
	end
end)

The other script puts a max people limit per type of SCP, but everyone was the same one. It is a script in ServerScriptService.

local SCPClass = game.ReplicatedStorage.SCPClass
local scp1 = game.ReplicatedStorage:FindFirstChild("173")
local SCPClass2 = game.ReplicatedStorage.SCPClass
local scp2 = game.ReplicatedStorage:FindFirstChild("049")
local SCP173FOVEVENT = game.ReplicatedStorage.scp173fovevent
local Max173 = false
local Max049 = false
local scpscript = scp1.Script
function scp173()
	if Max173 == false then
		Max173 = true
		scpClone = scp1:Clone()
		scpscriptclone = scpscript:Clone()
		scpClone.Name = "StarterCharacter"
		scpClone.Parent = game.StarterPlayer
		scpscriptclone.Parent = game.StarterPlayer.StarterCharacterScripts
		SCP173FOVEVENT:Fire()
	else if Max173 == true then
			if Max049 == false then
			Max049 = true
			scpClone2 = scp2:Clone()
			scpClone2.Name = "StarterCharacter"
			scpClone2.Parent = game.StarterPlayer
			end
		end
	end
end
SCPClass.Event:Connect(scp173)

You didn’t put local infront of

Players = game:GetService(“Players”)
In order for this to work you need to put local so it can be a variable you can use.

It should be elseif not else if for the second script. Very minor mistakes here. That should fix it though.

That’s not it, when you don’t precede something with ‘local’, it gets defined globally, still works though - it’s optimization to define everything locally for faster access to values.

Won’t affect the final outcome though, will still work.

If you defined Players already right before the function, why can’t you just do

Players.PlayerAdded -- instead?
2 Likes

Shouldn’t you add 1 to the number of SCPS?

Also is this supposed to morph one player into that SCP?

1 Like

yes, but if someone is already that SCP they become the other. And the morphing works

1 Like

because I don’t want everyone to become an SCP

You’re doing game.Players which is the same as game:GetService(“Players”) (except the latter methodology is better), that won’t affect anything related to what the SCP is.

1 Like

Putting the morph in the starter character folder will mean everyone will use that morph, so instead do something like:
morph = scp:Clone()
local oldCharacter = player.Character
player.Character = morph
oldCharacter:Remove()
morph.Parent = workspace

You can get the player from the event

1 Like

Would I do this?

local SCPClass = game.ReplicatedStorage.SCPClass
local scp1 = game.ReplicatedStorage:FindFirstChild("173")
local SCPClass2 = game.ReplicatedStorage.SCPClass
local scp2 = game.ReplicatedStorage:FindFirstChild("049")
local SCP173FOVEVENT = game.ReplicatedStorage.scp173fovevent
local player = game.Players.PlayerAdded
local Max173 = false
local Max049 = false
local scpscript = scp1.Script
function scp173()
	if Max173 == false then
		Max173 = true
		morph = scp1:Clone()
		local oldCharacter = player.Character
		player.Character = morph
		oldCharacter:Remove()
		morph.Parent = workspace
		scpscriptclone = scpscript:Clone()
		scpscriptclone.Parent = game.StarterPlayer.StarterCharacterScripts
		SCP173FOVEVENT:Fire()
	else if Max173 == true then
			if Max049 == false then
			morph2 = scp1:Clone()
			local oldCharacter2 = player.Character
			player.Character = morph
			oldCharacter2:Remove()
			morph2.Parent = workspace
			end
		end
	end
end
SCPClass.Event:Connect(scp173)

Yes but you need to get the player, e.g

then on the script that is firing the event, pass on the player variable

Change it to

1 Like

I get the error 17:25:55.473 - ServerScriptService.SCP:16: attempt to index nil with ‘Remove’
on this line

		oldCharacter:Remove()

Oops sorry, I just looked at one of my morph scripts and you don’t actually need that line or the old character

The only other thing is to rename the morph to the player’s name so:
morph.Name = player.Name

1 Like

now I get the error
17:31:49.513 - The current identity (2) cannot set a Character’s name (lacking permission 4)
on this

morph.Name = player.Name
1 Like

Did you put this line before you set player.Character to the morph?

1 Like

So it should be:
morph = scp1:Clone()
morph.Name = player.Name
player.Character = morph
morph.Parent = workspace

If it’s not in this order it doesn’t work

1 Like

now there are no errors, but it doesn’t morph the player

Oh I know why, when a player get’s that role, immediatly when they spawn they reset/die and turn into their normal character, but idk how to fix that