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

I've been trying to fix this for 30 minutes... Any way to fix this script?[EDITED]

Asked by 8 years ago
Edited 8 years ago

Here's the script:

player = game.Players.LocalPlayer
Bought = script.Parent.Bought
Bought.Value = false

local HireCost = Instance.new("IntValue")
HireCost.Parent = player
HireCost.Value = 10

script.Parent.MouseButton1Click:connect(function(Building)
    local leaderstats = player:FindFirstChild("leaderstats")
    local mg = script.Parent:WaitForChild("HireMoney")
    if leaderstats.Cash.Value >= HireCost.Value then
         player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost.Value
        if Bought.Value == false then
            Bought.Value = true
            HireCost.Value = HireCost.Value*2
            mg.Value = mg.Value + 1
        end
        script.Parent.Text = 'Hire Bil for $'..HireCost.Value
    end
end)

There is also another script in the button:

while true do
    local player = game.Players.LocalPlayer
    Bought = script.Parent.Bought
    local mg = script.Parent:WaitForChild("HireMoney")
    wait(0.5)
    if Bought.Value == true then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + mg.Value
    elseif Bought.Value == false then
    --Nothing Should Happen If It Has Not Been Bought
    end
end 

It works perfectly in studio, but doesn't work in-game.This is a Local Script. Please fix this. Thanks!

0
Is your game FE? User#5423 17 — 8y
0
No SmxkePurpp 50 — 8y

1 answer

Log in to vote
0
Answered by
nanaluk01 247 Moderation Voter
8 years ago
Edited 8 years ago

You could try to see if this works:

player = game.Players.LocalPlayer
Bought = script.Parent.Bought
Bought.Value = false

local HireCost = Instance.new("IntValue")
HireCost.Parent = player
HireCost.Value = 10

script.Parent.MouseButton1Click:connect(function(Building)
    local leaderstats = player:FindFirstChild("leaderstats")
    local mg = script.Parent:WaitForChild("HireMoney")
    if leaderstats.Cash.Value >= HireCost.Value then
        if Bought.Value == false then
            Bought.Value = true
            HireCost.Value = HireCost.Value*2
            mg.Value = mg.Value + 1
        end
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost.Value
    end
end)

And Put This Into Another localscript with the same parent as you other script:

while true do
    local player = game.Players.LocalPlayer
    Bought = script.Parent.Bought
    local mg = script.Parent:WaitForChild("HireMoney")
    wait(0.5)
    if Bought.Value == true then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + mg.Value
    end
    elseif Bought.Value == false then
    --Nothing Should Happen If It Has Not Been Bought
    end
end
0
Still will not work. SmxkePurpp 50 — 8y
0
Remember to explain what you are doing differently, that way the OP can understand what your code does compared to his. shayner32 478 — 8y
0
Fixed an error in your script. The errors were: if leaderstats.Cash.Value >= HireCost then, it supposed to be if leaderstats.Cash.Value >= HireCost.Value then second error: player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost, supposed to be player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost.Value SmxkePurpp 50 — 8y
0
But it works. Only in studio, not in-game. SmxkePurpp 50 — 8y
0
Try it in-game, and if it does not work, open the developer console and look for errors. Then fix the errors. nanaluk01 247 — 8y
Ad

Answer this question