Hey! I've been having a slight problem with this game I'm making. In the game, if you're within a certain distance of a tool you can pick it up with the "e" key, that works perfectly fine. But when I pick up the radio tool it does not work.

Info on the radio: The radio works when placed in starterpack but not when cloned in the inventory. It's the golden boombox model but I added a different mesh to it. All of the other tools work when they're cloned to the backpack just not the boombox. The BoomBox has a server and localscript and there is a remote event in Replicated Storage.

Here is the script to clone the boombox into the backpack when the e key is pressed and you're close enough to it. It's a localscript in StarterGui.

local run = game:GetService("RunService")
local aggro = 8
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

run.RenderStepped:Connect(function()
	local character = player.Character or player.CharacterAdded:Wait()
	if(workspace.House.Radio.Position - character:WaitForChild("Head").Position).Magnitude < aggro then
		mouse.KeyDown:Connect(function(key)
			key = key:lower()
			if key == "e" then
				local radio = game.ReplicatedStorage.Tools:WaitForChild("BoomBox"):Clone()
				radio.Parent = player.Backpack
				workspace.House.Radio:Destroy()
				script:Destroy()
			end
		end)
	end
end)

Please help! Thanks!

4 comments

1

Just so you know, mouse.KeyDown is deprecated. Use UserInputService.InputBegan:Connect(function(input)

0

@b_mni You should use the 2nd parameter of InputBegan, because if you won't use it, someone might be chatting, and if they press E, then it will fire even though they didn't want to press it.

0

Its a local script copying something therfore the server doesn't see it. either use a remote event or a non local script

0

Oh sorry I use it in a game that doesn't have chat or textboxes.