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

How can I remove things or change a value in the player? (FE)

Hi, I've been trying to make a sword equip with a button press and then get removed when I press that same button. It worked fine without FE, but when I transferred the script to FE, I haven't been able to remove it. I also tried separating the scripts into separate ones, but that didn't help either. I'm a newbie to Filtering Enabled, and it broke one of my previous games that I had been scripting. I'm using cloning and welding to put the sword in the hand. Also, I've been working on dual wielding a sword and a shield. (although that's not really relevant right now.) I'll put my code just in case if it helps anything. OLD Local side:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(keyF)
	if keyF == 'f' then
		game.ReplicatedStorage.Equip:FireServer()
	end
	
end)

New Local side; thanks NiniBlackJackQc!:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		game.ReplicatedStorage.Equip:FireServer()
	end
	
end)

Server side:

 game.ReplicatedStorage.Equip.OnServerEvent:Connect(function(player)
	local Character = player.Character
	local hand = Character.RightHand
	local Equipy = player.Character.Values.Equip.Value
	local Unsheath = script.Weapons.MasterSword.attack.Animations.Unsheath
	local sheathUn = Character.Humanoid:LoadAnimation(Unsheath)
	
	if Equipy == true then
		wait()
		sheathUn:Play()
		local sword = script.Weapons.MasterSword
		local cloneSword = sword:Clone()
		local scriptt = cloneSword.attack
		cloneSword.Parent = Character
		cloneSword.Union.Anchored = false
		cloneSword.Handle.Anchored = false
		local weld = Instance.new("Weld")
		weld.Parent = cloneSword.Handle
		weld.Part0 = Character.RightHand
		weld.Part1 = cloneSword.Handle
		scriptt.Disabled = false
		Equipy = false
		
	end
end)

Also, please report any errors in my code. Thanks :D

2 comments

0
0

Thanks for pointing that out :D

1 answer

Found a solution thanks to NiniBlackJackQc telling me that Mouse is deprecated. Local side:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Equip = true
UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.F and Equip == true then
		game.ReplicatedStorage.Equip:FireServer()
		Equip = false
	elseif input.KeyCode == Enum.KeyCode.F and Equip == false then
		game.ReplicatedStorage.Unequip:FireServer()
		Equip = true
	end
	
end)

Server side now consists of two scripts. One for cloning, and one for removing. Server side(equiping):

 game.ReplicatedStorage.Equip.OnServerEvent:Connect(function(player)
	local Character = player.Character
	local hand = Character.RightHand
	local Unsheath = script.Weapons.MasterSword.attack.Animations.Unsheath
	local sheathUn = Character.Humanoid:LoadAnimation(Unsheath)
	local Equipy = true	
	if Equipy == true then
		wait()
		Equipy = false
		sheathUn:Play()
		local sword = script.Weapons.MasterSword
		local cloneSword = sword:Clone()
		local scriptt = cloneSword.attack
		cloneSword.Parent = Character
		cloneSword.Union.Anchored = false
		cloneSword.Handle.Anchored = false
		local weld = Instance.new("Weld")
		weld.Parent = cloneSword.Handle
		weld.Part0 = hand
		weld.Part1 = cloneSword.Handle
		scriptt.Disabled = false
	end
end)

Server side(removing):

game.ReplicatedStorage.Unequip.OnServerEvent:connect(function(player)
	local Char = player.Character
	local equip = true
	local anim = script.Animations.Unsheath
	local animPlay = Char.Humanoid:LoadAnimation(anim)
	if equip == true then
		animPlay:Play()
		Char.MasterSword:Destroy()
	end
	
end)

The problem was that since Mouse was deprecated, it couldn't make the bool value called Equip on the local side true or false. So don't use the things if they're deprecated. (this should be obvious, but I didn't know that Mouse was deprecated)

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