Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats wrong with this .Chatted?

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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.
0
Nope, same error. ggggyourface23 63 — 10y
0
Now the error is on line 4. Same error as before but just a different line... ggggyourface23 63 — 10y
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. Spongocardo 1991 — 10y
Ad

Answer this question