Here's the script:
01 | player = game.Players.LocalPlayer |
02 | Bought = script.Parent.Bought |
03 | Bought.Value = false |
04 |
05 | local HireCost = Instance.new( "IntValue" ) |
06 | HireCost.Parent = player |
07 | HireCost.Value = 10 |
08 |
09 | script.Parent.MouseButton 1 Click:connect( function (Building) |
10 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
11 | local mg = script.Parent:WaitForChild( "HireMoney" ) |
12 | if leaderstats.Cash.Value > = HireCost.Value then |
13 | player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost.Value |
14 | if Bought.Value = = false then |
15 | Bought.Value = true |
There is also another script in the button:
01 | while true do |
02 | local player = game.Players.LocalPlayer |
03 | Bought = script.Parent.Bought |
04 | local mg = script.Parent:WaitForChild( "HireMoney" ) |
05 | wait( 0.5 ) |
06 | if Bought.Value = = true then |
07 | player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + mg.Value |
08 | elseif Bought.Value = = false then |
09 | --Nothing Should Happen If It Has Not Been Bought |
10 | end |
11 | end |
It works perfectly in studio, but doesn't work in-game.This is a Local Script. Please fix this. Thanks!
You could try to see if this works:
01 | player = game.Players.LocalPlayer |
02 | Bought = script.Parent.Bought |
03 | Bought.Value = false |
04 |
05 | local HireCost = Instance.new( "IntValue" ) |
06 | HireCost.Parent = player |
07 | HireCost.Value = 10 |
08 |
09 | script.Parent.MouseButton 1 Click:connect( function (Building) |
10 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
11 | local mg = script.Parent:WaitForChild( "HireMoney" ) |
12 | if leaderstats.Cash.Value > = HireCost.Value then |
13 | if Bought.Value = = false then |
14 | Bought.Value = true |
15 | HireCost.Value = HireCost.Value* 2 |
16 | mg.Value = mg.Value + 1 |
17 | end |
18 | player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - HireCost.Value |
19 | end |
20 | end ) |
And Put This Into Another localscript with the same parent as you other script:
01 | while true do |
02 | local player = game.Players.LocalPlayer |
03 | Bought = script.Parent.Bought |
04 | local mg = script.Parent:WaitForChild( "HireMoney" ) |
05 | wait( 0.5 ) |
06 | if Bought.Value = = true then |
07 | player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + mg.Value |
08 | end |
09 | elseif Bought.Value = = false then |
10 | --Nothing Should Happen If It Has Not Been Bought |
11 | end |
12 | end |