|
| 30 Dec 2013 02:49 AM |
I've ran into a problem that I can't seem to fix in my script... What this script does is basically allowing a player to buy a house subtract X amount of money from their leaderstats, but if the player leaves the house goes for sale again.
Thats where I'm having my problem is where the Player is leaving the server, I can't get the PlayerRemoving line (all the way to the bottom) to fire, and if it is I wouldn't know.
print("Debugging House Owner Script.".." : ".."Script is located in "..script.Parent.Name) local house = script.Parent local frontdoor = house:findFirstChild("Frontdoor") local backdoor = house:findFirstChild("Backdoor") local ownerGui = frontdoor:findFirstChild("OwnerGui") local owner = nil local cost = 100 ------------------ local second = 1 local minute = 60 local day = 24 local MaxTime = 10--second*minute*day local Time = 10 --MaxTime ------------------ local saleColor = Color3.new(255/255, 0/255, 0/255) local purchasedColor = Color3.new(255/255, 255/255, 0/255)
frontdoor.ClickDetector.MouseClick:connect(function(player) if owner == nil and player:findFirstChild("leaderstats").Money.Value >= cost then owner = player.Name print(owner) ownerGui.Owner.Text = "Owned by "..owner ownerGui.Owner.TextColor3 = purchasedColor local cash = player:findFirstChild("leaderstats").Money cash.Value = cash.Value - cost else ownerGui.Owner.Text = "Already owned!" wait(1) ownerGui.Owner.Text = "Owned by "..owner end end)
function sell() owner = nil ownerGui.Owner.Text = "For Sale!" ownerGui.Owner.TextColor3 = saleColor Time = MaxTime end
function ownerLeft(player) if player == owner then print("Owner left server, selling house!") sell() end end
while true do if owner ~=nil then Time = Time - 1 --print("MaxTime is "..MaxTime) print("Time left "..Time) if Time == 0 then if game.Players:findFirstChild(owner).leaderstats.Money.Value >= cost then Time = MaxTime print(Time) local cash = game.Players:findFirstChild(owner):findFirstChild("leaderstats").Money cash.Value = cash.Value - cost else print("Bankrupt") sell() end end end wait(1) end
game.Players.PlayerRemoving:connect(ownerLeft)
No output errors because the PlayerRemoving line never fires. |
|
|
| Report Abuse |
|
Usering
|
  |
| Joined: 18 Aug 2012 |
| Total Posts: 10281 |
|
|
| 30 Dec 2013 03:14 AM |
Are you testing this in Studio or in game?
My Roblox API: https://twitter.com/Mineshifted/status/417583341013962752 |
|
|
| Report Abuse |
|
DataStore
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 8540 |
|
|
| 30 Dec 2013 03:45 AM |
| Put the connection line above the loop. |
|
|
| Report Abuse |
|