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

Whats wrong with this .Chatted?

What it should do is when you say ssj it changes your walkspeed and health, and when you say off it changes it back to normal.

local Player = game.Players.LocalPlayer
function ssj(msg)
	ssj = false
	if msg == "ssj" and ssj == false then
		ssj = true
		Player.Character.Humanoid.WalkSpeed = 60
		Player.Character.Humanoid.MaxHealth = 120
	end
end

function off(msg)
if ssj == false and msg == "ssj" then
		ssj = false
		Player.Character.Humanoid.WalkSpeed = 16
		Player.Character.Humanoid.MaxHealth = 100
	end
end

script.Parent.Parent.Chatted:connect(ssj)
script.Parent.Parent.Chatted:connect(off)

Error: Players.ggggyourface23.Backpack:6:attempt to index upvalue 'Player' ( a nil value ) line:4

1 answer

The error itself confused me so I looked at the line number it gave. It is giving you an error because WalkSpeed is not a valid member of the player's character. What you need to do is add .Humanoid before .WalkSpeed.

Also, you can make the script more efficient and have less functions by putting it all into one function and by using an anonymous function, like this:

local Player = game.Players.LocalPlayer
ssj = false --Putting the variable outside of the function so we can access it anywhere in the script.

Player.Chatted:connect(function(msg) --Anonymous function so you don't need the connect line for the function to fire when the event occurs. 
	if msg == "ssj" and ssj == false then --If ssj is false and the message is ssj then.
		ssj = true
		Player.Character.Humanoid.WalkSpeed = 60
		Player.Character.Humanoid.MaxHealth = 120
	elseif ssj == true and msg == "ssj" then --Elseif ssj is true and the message is ssj then.
		ssj = false
		Player.Character.Humanoid.WalkSpeed = 16
		Player.Character.Humanoid.MaxHealth = 100
	end
end) --The bracket after the end closes the anonymous function.

3 comments

0

Nope, same error.

0

Now the error is on line 4. Same error as before but just a different line...

0

Try changing the Player variable to point to "script.Parent.Parent". Reason being is because the script is in the player's backpack. If not, try making the P in Player uncapitalised or get rid of the local before Player.

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