I have 2 scripts. A house owner script and a keycard giver script. How do I mash these 2 together to make 1 script?
House script:
local ting = 0 --debouncer owner = script.Parent.Parent.Parent.OwnerName --This is the thing that holds the owners name function onTouched(hit) if ting == 0 then --debounce check ting = 1 --activate debounce check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button if check ~= nil then --If a human is found, then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players if (user:FindFirstChild("House") ~= nil) then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players local message = Instance.new("Message") --make a message message.Text = "You already own a House" --Put text into the message message.Parent = user --Display message to new owner only wait(3) --Wait to let the message display for a while message:remove() --Remove the message from the new owner else local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players owner.Value = hit.Parent.Name --save new owners name for later. local own = Instance.new("IntValue") own.Name = "House" own.Parent = user local message = Instance.new("Message") --make a message message.Text = "You now own this House!" --Put text into the message message.Parent = user --Display message to new owner only wait(3) --Wait to let the message display for a while message:remove() --Remove the message from the new owner script.Parent.Parent:remove() end end ting = 0 --remove debounce end end script.Parent.Touched:connect(onTouched) --Start listening for button-touchers.
Keycard giver script
print("Shop Script Loaded") Door = script.Parent local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onTouched(hit) if debounce == false then local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end local player = getPlayer(human) debounce = true if (player == nil) then return end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Money") if sp == nil then return false end if (sp.Value >=0) then --Amount of how much the weapon will go for sp.Value = sp.Value - 0 --Put the same exact number here as you did above print("Enough Money") game.Lighting.Keycard13:clone().Parent = player.Backpack --Change NAMEOFTOOLHERE to your tool name Door.BrickColor = BrickColor.new(37) --MAKE SURE YOU PUT THE WEAPON INTO LIGHTING wait(2) Door.BrickColor = BrickColor.new(21) --Leave the rest of this alone debounce = false else debounce = false end end end connection = Door.Touched:connect(onTouched) --
It's kind of hard to understand what you're saying, but I think you either mean you want them both to run at the same time, or just want them as one script.
If you want them to run both at once, then you can convert the function into a coroutine. Example:
function hello() print("hi") end hello() --that would turn into this VV local hello = coroutine.wrap(function() print('hi') end) hello() --using a coroutine allows you to run multiple blocks of code at once.
See here: http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines
If you mean you want them to just be in one script, then you don't have to really do any work. Just put them in one script.
local ting = 0 --debouncer owner = script.Parent.Parent.Parent.OwnerName --This is the thing that holds the owners name function onTouched(hit) if ting == 0 then --debounce check ting = 1 --activate debounce check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button if check ~= nil then --If a human is found, then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players if (user:FindFirstChild("House") ~= nil) then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players local message = Instance.new("Message") --make a message message.Text = "You already own a House" --Put text into the message message.Parent = user --Display message to new owner only wait(3) --Wait to let the message display for a while message:remove() --Remove the message from the new owner else local user = game.Players:GetPlayerFromCharacter(hit.Parent) --Find human among the players owner.Value = hit.Parent.Name --save new owners name for later. local own = Instance.new("IntValue") own.Name = "House" own.Parent = user local message = Instance.new("Message") --make a message message.Text = "You now own this House!" --Put text into the message message.Parent = user --Display message to new owner only wait(3) --Wait to let the message display for a while message:remove() --Remove the message from the new owner script.Parent.Parent:remove() end end ting = 0 --remove debounce end end script.Parent.Touched:connect(onTouched) --Start listening for button-touchers. ------------------------------------- --Here is the second part print("Shop Script Loaded") Door = script.Parent local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onTouched(hit) if debounce == false then local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end local player = getPlayer(human) debounce = true if (player == nil) then return end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Money") if sp == nil then return false end if (sp.Value >=0) then --Amount of how much the weapon will go for sp.Value = sp.Value - 0 --Put the same exact number here as you did above print("Enough Money") game.Lighting.Keycard13:clone().Parent = player.Backpack --Change NAMEOFTOOLHERE to your tool name Door.BrickColor = BrickColor.new(37) --MAKE SURE YOU PUT THE WEAPON INTO LIGHTING wait(2) Door.BrickColor = BrickColor.new(21) --Leave the rest of this alone debounce = false else debounce = false end end end connection = Door.Touched:connect(onTouched) --
Nothing much would change. If this helped, please accept the answer. Thanks