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

Script not working, can someone help? [ The "1 Answer" is an attempted fix ]

Asked by
hudzell 238 Moderation Voter
10 years ago

This script is used in hudzell's Parkour Battles as a healing script

-- UPDATE, SCROLL DOWN --

What is wrong with this LocalScript that makes it work properly only in solo mode but acts like it's a button with no script in multiplayer?

local button = script.Parent
player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
local Blur = script.Parent.Parent.Blur

function onClicked()
    Heal()
end

button.MouseButton1Click:connect(onClicked)

function Heal()
    if script.Parent.Text == "Heal" then
        script.Walkspeed.Value = character.Humanoid.WalkSpeed
        character.Humanoid.WalkSpeed = 0
        Blur.Visible = true
        Blur.BackgroundTransparency = .5
        local healFire = script.HealFire:Clone()
        local healLight = script.HealLight:Clone()
        local healSparkles = script.HealSparkles:Clone()
        healLight.Parent = character.Torso
        healFire.Parent = character.Torso
        healSparkles.Parent = character.Torso
        for i = 1, 100 do
            local newHealth = character.Humanoid.Health + 2
            if newHealth < 100 then
                wait(.001)
                character.Humanoid.Health = newHealth
            else
                character.Humanoid.Health = character.Humanoid.MaxHealth
            end
        end
        Blur.Visible = false
        Blur.BackgroundTransparency = 1
        healFire.Enabled = false
        healLight.Enabled = false
        healSparkles.Enabled = false
        character.Humanoid.WalkSpeed = script.Walkspeed.Value
        button.Text = "Wait: 5"
        wait(1)
        button.Text = "Wait: 4"
        wait(1)
        button.Text = "Wait: 3"
        wait(1)
        button.Text = "Wait: 2"
        wait(1)
        button.Text = "Wait: 1"
        wait(1)
        healFire:remove()
        healLight:remove()
        healSparkles:remove()
        button.Text = "Heal"
    end
end


Update: I changed the script a little at the top

local button = script.Parent
player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
local Blur = script.Parent.Parent.Blur

script.Parent.MouseButton1Down:connect(function()
    if script.Parent.Text == "Heal" then
        script.Walkspeed.Value = character.Humanoid.WalkSpeed
        character.Humanoid.WalkSpeed = 0
        Blur.Visible = true
        Blur.BackgroundTransparency = .5
        local healFire = script.HealFire:Clone()
        local healLight = script.HealLight:Clone()
        local healSparkles = script.HealSparkles:Clone()
        healLight.Parent = character.Torso
        healFire.Parent = character.Torso
        healSparkles.Parent = character.Torso
        for i = 1, 100 do
            local newHealth = character.Humanoid.Health + 2
            if newHealth < 100 then
                wait(.001)
                character.Humanoid.Health = newHealth
            else
                character.Humanoid.Health = character.Humanoid.MaxHealth
            end
        end
        Blur.Visible = false
        Blur.BackgroundTransparency = 1
        healFire.Enabled = false
        healLight.Enabled = false
        healSparkles.Enabled = false
        character.Humanoid.WalkSpeed = script.Walkspeed.Value
        button.Text = "Wait: 5"
        wait(1)
        button.Text = "Wait: 4"
        wait(1)
        button.Text = "Wait: 3"
        wait(1)
        button.Text = "Wait: 2"
        wait(1)
        button.Text = "Wait: 1"
        wait(1)
        healFire:remove()
        healLight:remove()
        healSparkles:remove()
        button.Text = "Heal"
    end
end)


0
Is this a LocalScript? What is it supposed to do that it is not doing? AxeOfMen 434 — 10y
0
It's not doing anything in multiplayer, it acts like it's a button with no script in it. But in solo mode it works perfectly. hudzell 238 — 10y
0
Does anyone know a place output GUI that I can use? I might be able to figure it out if I can find one. hudzell 238 — 10y
0
Wow, thank you so much Bebee2, it worked! :D hudzell 238 — 10y

2 answers

Log in to vote
0
Answered by
Bebee2 195
10 years ago

Huh... My post didn't post.

So the problem most likely is that you declared player before player actually fully loaded.

It's a common error with local scripts in PlayerGui or Backpack that defines player at the top.

What you do is just add this one-liner to the top:

repeat wait() until game.Players.LocalPlayer

Tell us what happens now.

0
And it never hurts to use WaitForChild when declaring objects. I don't run into that problem as much, though. Bebee2 195 — 10y
Ad
Log in to vote
0
Answered by
hudzell 238 Moderation Voter
10 years ago

[ DID NOT WORK ]

Wait a minute, I think I figured it out. The

function onClicked()
    Heal()
end

button.MouseButton1Click:connect(onClicked)

is above the actual function it's self (Heal()). So if I just use the updated script rather than the original, it should work, am I correct?

Sadly, this did not work. I still need help. :c

Answer this question