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

How do you make like a power up like walkspeed and max health when you touch a gui?

db = true
cooldown = script.Parent.Cooldown
Kaioken = script.Parent
local player = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")


Kaioken.MouseButton1Down:Connect(function()
	if db == true then
		player.MaxHealth.Value = player.MaxHealth.Value +5
		player.Walkspeed.Value = player.Walkspeed.Value +5
		wait (5)
		player.MaxHealth.Value = player.MaxHealth.Value -5
		player.Walkspeed.Value = player.Walkspeed.Value -5
		db = false
		cooldown.Text = "Cooldown: 5"
		wait (1)
		cooldown.Text = "Cooldown: 4"
		wait (1)
		cooldown.Text = "Cooldown: 3"
		wait (1)
		cooldown.Text = "Cooldown: 2"
		wait (1)
		cooldown.Text = "Cooldown: 1"
		wait(1)
		cooldown.Text = "Cooldown: 0"
		db = true
	end

end)

Thats my script I use and it says attempt to index upvalue 'player' (a nil value) Help meh plz

4 comments

0

The character was not loaded by the time the script ran

0

Additionally, you can use a for loop in lines 15 through 25. Also use local variables

0

How is the character not loaded

0

I still dont understand

1 answer

✓ Accepted answer

What incapaz said is correct. The gui usually loads before the player, so at the time the script ran, there was no LocalPlayer.Character

A hacky fix is to add wait()s to the beginning of your script, but that doesn't solve the problem. The proper way is to use some form of wait on the character. Here's one solution:

local db = true
local cooldown = script.Parent.Cooldown
local Kaioken = script.Parent
local player = game.Players.LocalPlayer
if not player.Character then
    player.CharacterAdded:wait()
end

local character = player.Character

if not character:FindFirstChild("Humanoid”) then
    character:WaitForChild(”Humanoid”)
end

local human = character.Humanoid


Remember that this is just one solution, and I'm sure there are better ways to do this. But that's for you to discover.

Even though you didn't ask, I'll fix the rest of your script, too.

Kaioken.MouseButton1Down:Connect(function()
    if db then
        db = false
        human.MaxHealth = human.MaxHealth +5
        human.Walkspeed = human.Walkspeed +5
        wait (5)
        human.MaxHealth = human.MaxHealth -5
        human.Walkspeed = human.Walkspeed -5

        for i = 5, 0, -1 do
            cooldown.Text = "Cooldown: "..i
            wait (1)
        end
        db = true
    end

end)

11 comments

1

seems i got this problem after that Players.HappyTimIsHim.PlayerGui.HealthandImage.Kaioken.LocalScript:17: attempt to index field 'MaxHealth' (a number value)

1

Oof, I'll fix it.

1

It's fixed.

0

is it human.MaxHealth.Value or just that

1

Try it.

0

Humanoid.MaxHealth is a number value, so it has no .Value property.

0

ooooooh

1

Hey, if the answer helped you should mark it as answer!

1

doesnt seem like cooldown.Text is working

0

Can you elaborate?

0

elaborate? my bad it does work sorry

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