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

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

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!

2 comments

0

Is your game FE?

0

No

1 answer

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

5 comments

0

Still will not work.

0

Remember to explain what you are doing differently, that way the OP can understand what your code does compared to his.

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

0

But it works. Only in studio, not in-game.

0

Try it in-game, and if it does not work, open the developer console and look for errors. Then fix the errors.

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