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

Super Saiyan Script works fine in studio but when it's in game it just doesn't work at all?

I created a chat command script that makes you able to go from super saiyan to super saiyan blue and it works fine in studio but in game it just doesn't work

Do I need to change anything or do I need to use local scripts?

Super saiyan chat command

game.Players.PlayerAdded:connect(function(p)
	p.Chatted:connect(function(msg)
		msg = msg:lower()
		if (msg == "ssj") then
			if (p.Character ~= nil) then
						game.Players.LocalPlayer.Character.gokuhair.ssj.Disabled = false
			end 
		end 
	end) 
end)	

Super saiyan god chat command

game.Players.PlayerAdded:connect(function(p)
	p.Chatted:connect(function(msg)
		msg = msg:lower()
		if (msg == "ssg") then
			if (p.Character ~= nil) then
						game.Players.LocalPlayer.Character.gokuhair.ssg.Disabled = false
			end 
		end 
	end) 
end)	

Super saiyan blue chat command

game.Players.PlayerAdded:connect(function(p)
	p.Chatted:connect(function(msg)
		msg = msg:lower()
		if (msg == "ssgss") then
			if (p.Character ~= nil) then
						game.Players.LocalPlayer.Character.gokuhair.ssgss.Disabled = false
			end 
		end 
	end) 
end)	

Tree

3 comments

0

connect is deprecated, use Connect

0

Changed :connect to :Connect but it still doesn't work

0

its because its decaperated

2 answers

✓ Accepted answer

#Ancestry

The top ancestor (excluding the DataModel and the Players service) of a LocalScript is, well, the LocalPlayer. And LocalScripts run for one client, you. Scripts run on the server, which is responsible for connecting all the players together in your game.

#Why LocalPlayer is nil on the server

Think of it as your school classmates and your teacher. Think of your school classmates as other clients, and think of your teacher as the server. If you told your teacher to get the local student, your teacher would be very confused, because which student is the local student? For this reason, LocalPlayer is nil on the server. Your game could have multiple players in it, and when you try using LocalPlayer, it can't just randomly pick a player. It makes no sense. Code cannot read your mind. This is why it must be all typed out. So instead of doing this:

make a part inside of the workspace with color red

You must do this:

local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Really red")
part.Parent = workspace 

With that in mind, let's fix up your script:

game.Players.PlayerAdded:Connect(function(p)
    p.Chatted:Connect(function(msg)
        msg = msg:lower()
        if msg == "ssj" and p.Character then
            p.Character.gokuhair.ssj.Disabled = false
        end 
    end) 
end)    

Pretty much for each time you say game.Players.LocalPlayer, you'd say p instead. PlayerAdded passes the player who joined, making this a whole lot easier.

The reason your script "worked" in Studio was because in Studio's Play Solo mode, there is no separation of the server and client. In order to get accurate results whilst using Play Solo, go to Settings>Studio>Use Accurate Play Solo

You can also use local servers to simulate a real game.

And finally, RBXScriptSignal:connect() with a lowercase 'c' is deprecated, use RBXScriptSignal:Connect() with an uppercase 'C'.

5 comments

1

Oof, green got here and helped me fix it before you did but appreciated for your support.

0

i'd appreciate it if you accepted this answer though, not mine

0

who got here first not me

0

i don't see why he shouldn't accept the better answer though, yours goes more indepth then mine

0

seems to.....

###Server Scripts and LocalPlayer

The server cannot use LocalPlayer. It will always return nil when used. This only applies to ingame, which is why it only works in studio. Luckily for you, you already have a player variable setup thanks to PlayerAdded!

###connect vs Connect

connect is deprecated. Please use Connect instead.

Updated code:

Super Saiyan chat command

game.Players.PlayerAdded:connect(function(p)
    p.Chatted:Connect(function(msg)
        msg = msg:lower()
        if (msg == "ssj") then
            if (p.Character ~= nil) then
                        p.Character.gokuhair.ssj.Disabled = false
            end 
        end 
    end) 
end)    

Super Saiyan god command

game.Players.PlayerAdded:Connect(function(p)
    p.Chatted:Connect(function(msg)
        msg = msg:lower()
        if (msg == "ssg") then
            if (p.Character ~= nil) then
                        p.Character.gokuhair.ssg.Disabled = false
            end 
        end 
    end) 
end)    

Super Saiyan blue chat command

game.Players.PlayerAdded:Connect(function(p)
    p.Chatted:Connect(function(msg)
        msg = msg:lower()
        if (msg == "ssgss") then
            if (p.Character ~= nil) then
                        p.Character.gokuhair.ssgss.Disabled = false
            end 
        end 
    end) 
end)    

1 comment

0

Thanks, I should really start smashing :Connect in my head and not use LocalPlayer.

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