usermvp
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 188 |
|
|
| 07 Feb 2016 03:06 PM |
So, what the morph script does is gives the player a sword and removes 2 other swords, Steel Sword and Gold Sword, but only if the swords are there. The problem is sometimes the swords won't change and then once they stop changing they won't change anymore.
Script:
script.Parent.Touched:connect(onTouch)
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 onTouch(part)
local human = part.Parent:findFirstChild("Humanoid") if (human == nil) then return end
local player = getPlayer(human)
if (player == nil) then return end
if not debounce then
debounce = true
-- Remove any other swords the player might have
local checkforsteelsword = player:FindFirstChild("Backpack"):FindFirstChild("Steel Sword") if checkforsteelsword ~= nil then checkforsteelsword:remove() end
local checkforgoldsword = player:FindFirstChild("Backpack"):FindFirstChild("Gold Sword") if checkforgoldsword ~= nil then checkforgoldsword:remove() end
local checkforwoodsword = player:FindFirstChild("Backpack"):FindFirstChild("Wood Sword") if checkforwoodsword == nil then print("No wood sword") game.ReplicatedStorage:findFirstChild("Wood Sword"):clone().Parent = player.Backpack script.Disabled = true wait(0.5) script.Disabled = false elseif checkforwoodsword then print("Wood sword found") end
wait(0.5)
debounce = true
end end script.Parent.Touched:connect(onTouch)
|
|
|
| Report Abuse |
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 07 Feb 2016 03:56 PM |
try making the parent of the sword = nil (the ones you want to remove) also Remove() is deprecated in favor of Destroy and ClearAllChildren
As it stands your script wont necessarily report the presence of a wooden sword IF one has just been added as the elseif would be out of scope in that circumstance.
i have doubts about calling script.Disabled from within a script - I don't think it works, probably not a good idea to have a wait() inside an if then elseif structure.
hope this helps |
|
|
| Report Abuse |
|