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

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

Asked by 5 years ago
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

0
The character was not loaded by the time the script ran User#19524 175 — 5y
0
Additionally, you can use a for loop in lines 15 through 25. Also use local variables User#19524 175 — 5y
0
How is the character not loaded HappyTimIsHim 652 — 5y
0
I still dont understand HappyTimIsHim 652 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)

1
seems i got this problem after that Players.HappyTimIsHim.PlayerGui.HealthandImage.Kaioken.LocalScript:17: attempt to index field 'MaxHealth' (a number value) HappyTimIsHim 652 — 5y
1
Oof, I'll fix it. protectiveebob 221 — 5y
1
It's fixed. protectiveebob 221 — 5y
0
is it human.MaxHealth.Value or just that HappyTimIsHim 652 — 5y
View all comments (7 more)
1
Try it. protectiveebob 221 — 5y
0
Humanoid.MaxHealth is a number value, so it has no .Value property. protectiveebob 221 — 5y
0
ooooooh HappyTimIsHim 652 — 5y
1
Hey, if the answer helped you should mark it as answer! Aimarekin 345 — 5y
1
doesnt seem like cooldown.Text is working HappyTimIsHim 652 — 5y
0
Can you elaborate? protectiveebob 221 — 5y
0
elaborate? my bad it does work sorry HappyTimIsHim 652 — 5y
Ad

Answer this question