Thank you, in advance, for the help :) So I created a "swordSummoning" (local) script located in StarterPlayerScripts. It's meant to equip the user with a sword once the 'r' key is pressed. Each time the function is called, the sword appears for about a second or two, then completed disappears. On top of that, the sword's "handle" does not appear.
Here is the code within the Summoning script:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() hasSword= false Mouse.KeyDown:connect(function(Key) if Key == "r" and hasSword == false then --If the key is pressed and player does not have a sword hasSword= true --Make the hasSword variable true clone = game.Lighting.Sword:Clone() --Create a clone of the sword clone.Parent = game.Players.LocalPlayer.Character --Put the sword on the character print("Worked") --Print "Worked" for assurance else --If you do have the sword clone:Destroy() --Remove it hasSword= false --Make it false end end)
I tried to get rid of this...:
else --If you do have the sword clone:Destroy() --Remove it hasSword= false --Make it false
...but nothing changed. I still got the same problem. So I'm starting to think that it doesn't have anything to do with the Summoning script
Question: Is the script the problem? If yes, how can I fix the script?
Since the beginning of the if statement has
If Key == "r"
that part of the if statement and only the function below it will work if they key is R
On the other hand the
else
at line 10 doesn't have "If Key == "r"" Therefore that function can be triggered by any button.
Sorry if I'm not good with explanations, but that's why it's disappearing. Just change the else to
elseif Key == "r" then
then you'll be good.