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: Trouble With Tycoon Door

Previous Thread :: Next Thread 
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 03:15 PM
Hello, I was wondering if you can tell me what is wrong with this script. It is yelling at me for line sixtrying to index plr.

function onTouched(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
local hitname = hit.Parent.Name
local plr = game.Players:FindFirstChild(hitname)
local to = Instance.new("StringValue")
local tycooncheck = plr:FindFirstChild("TycoonOwner")
if Humanoid ~= nil then
if tycooncheck == nil then
to.Name = "TycoonOwner"
to.Parent = plr
to.Value = hitname
elseif tycooncheck ~= nil then
print("You Have A Tycoon Already! You Can Only Have One!")
end
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:17 PM
You have
local plr = game.Players:FindFirstChild(hitname)

Should be
local plr = game.Players:FindFirstChild(hit.name)
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:18 PM
Oh and Name has to be capitalized
local plr = game.Players:FindFirstChild(hit.Name)
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:19 PM
fail just noticed the hitname variable
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 03:21 PM
I have a variable that is hit.Parent.Name the name of the variable is hitname
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:22 PM
try
local plr = game.Players:getPlayerFromCharacter(hit.Parent)
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 03:27 PM
I think that worked... But it still yelled at me.... Hm. It is telling me it is a nil value, would it still do that even if I have that check for seeing if it is nil?
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 03:28 PM
And now it isn't working for a some reason.
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:31 PM
Yeah you need an if statement, you can't just assign variables without checking if they are there.
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:34 PM
Like this

function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then --First we see if Humanoid is a parent of hit
local Humanoid = hit.Parent:FindFirstChild("Humanoid") --Then we assign Humanoid
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 03:34 PM
I do, though. It is seeing if it equals nil or not. If it does, then it creates it. If it does and it has a value it prints that you have one. If it isn't the correct one could you explain what one I need?
Report Abuse
ninetailfox73 is not online. ninetailfox73
Joined: 11 Mar 2008
Total Posts: 1954
14 Jul 2013 03:36 PM
oh wow I'm blind
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 04:01 PM
If no one can fugure it out then I can just put it in the model... I would like it if I could put it in the player though.
Report Abuse
NVianney is not online. NVianney
Joined: 24 Mar 2012
Total Posts: 173
14 Jul 2013 04:09 PM
if (hit.Parent:findFirstChild("Humanoid") == nil then return end
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
Report Abuse
NVianney is not online. NVianney
Joined: 24 Mar 2012
Total Posts: 173
14 Jul 2013 04:10 PM
Fixed version:

if (hit.Parent:findFirstChild("Humanoid") == nil) then return end
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 04:19 PM
How would I implement that exactly? If that is checking if the humanoid exists then I have it already. Just in a different format.
Report Abuse
NVianney is not online. NVianney
Joined: 24 Mar 2012
Total Posts: 173
14 Jul 2013 04:24 PM
I'll post the whole source code.


function onTouched(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if (Humanoid ~= nil) then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local to = Instance.new("StringValue")
local tycooncheck = plr:FindFirstChild("TycoonOwner")
if tycooncheck == nil then
to.Name = "TycoonOwner"
to.Parent = plr
to.Value = hit.Parent.Name
elseif tycooncheck ~= nil then
print("You Have A Tycoon Already! You Can Only Have One!")
end
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
mostwanted1 is not online. mostwanted1
Joined: 21 Dec 2010
Total Posts: 511
14 Jul 2013 04:37 PM
Wow, that worked! So how does putting Humanoid ~= nil in ()'s fix it?
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Jul 2013 04:45 PM
script.Parent.Touched:connect(function(hit)
local H = hit.Parent:findFirstChild("Humanoid")
if H ~= nil then
local P = game.Players:GetPlayerFromCharacter(hit.Parent)
if P ~= nil then
P:Destroy()
end end end)

Trust me. ;D
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