Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does the sword disappear a second after being "Summoned"?

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?

1 comment

1

You should never use Mouse.Keydown! It's deprecated!

1 answer

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.

4 comments

0

That didn't work

0

But thank you for the help!

0

Downvoted for encouraging use of Mouse.Keydown

0

It's deprecated, that's why. Here's a wiki page: http://wiki.roblox.com/index.php?title=Keyboard_input

This discussion is preserved as it was. New answers, comments, and votes are closed.