generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: PlayerRemoving Problem.

Previous Thread :: Next Thread 
GuestCapone is not online. GuestCapone
Joined: 19 Oct 2012
Total Posts: 1928
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 is online. 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 is not online. DataStore
Joined: 07 Feb 2012
Total Posts: 8540
30 Dec 2013 03:45 AM
Put the connection line above the loop.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image