You can write your topic however you want, but you need to answer these questions:
Hello! I have a game and when you step on a part then the game can run a certain function so that when you press ‘E’ the game puts a tool in your backpack.
The feature was working but not doing as expected. So the tool was working though you can press ‘E’ anywhere in the map and thats the problem. I want it so you can only collect the tool pressing a certain distance away.
The thing thats driving me nuts is that the game is reading ‘game’ as a error.
I have above tried a solution above.
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
function iftouch()
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
game.ReplicatedStorage.Tool.Parent = game.Players.LocalPlayer.Backpack
end
end
game.Workspace.Plate.Touched:Connect(iftouch) -- this is the part where is messes up.
Here is a error in the output.
Or in a more simple way of saying this is that the script is not working.
You just need a ‘)’ to close the end for the InputBegan function.
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
function iftouch()
UIS.InputBegan:Connect(function(keyCode)
if keyCode.KeyCode == Enum.KeyCode.E then
game.ReplicatedStorage.Tool.Parent = game.Players.LocalPlayer.Backpack
end
end)
end
game.Workspace.Plate.Touched:Connect(iftouch) -- this is the part where is messes up.
And when it says it got game, it was expecting a ) but it only got game.
You forgot an “end” and a “)”.
This is the polished code I came up with:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HumanoidRootPart = Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
function onTouch()
UserInputService.InputBegan:Connect(
function(keyCode)
if keyCode.KeyCode == Enum.KeyCode.E then
ReplicatedStorage.Tool.Parent = Players.LocalPlayer.Backpack
end
end
)
end
workspace.Plate.Touched:Connect(onTouch)
1 Like
Er, my solution should fix that.
1 Like
I edited it, but scripter’s will work too, you just need to change keyCode.keyCode to keyCode.KeyCode if you use his
1 Like