✓ Accepted answer
You can't run a LocalScript from inside a brick like that. You could do something like below, but it'll need to be in a LocalScript in a place where it can run, like StarterCharacterScripts.
This script keeps a tag in your player while you're touching your brick. If the tag is there and you press Q, the function will run. If you wanted something else, you should explain further~
local player = game.Players.LocalPlayer
local char = player.Character
local input = game:GetService('UserInputService')
local part = Workspace:WaitForChild('Part')
local debounce = Instance.new("StringValue")
debounce.Name = "Touching"
local function isDebounce()
return player:findFirstChild("Touching")
end
local function isPlayer(hit)
if hit and hit.Parent then
local playerHit = game.Players:GetPlayerFromCharacter(hit.Parent)
if playerHit and playerHit == player then
return true
end
end
return false
end
part.Touched:connect(function(hit)
if isPlayer(hit) then
local isDebounce = isDebounce()
if not isDebounce then
debounce:Clone().Parent = player
end
end
end)
part.TouchEnded:connect(function(hit)
if isPlayer(hit) then
local isDebounce = isDebounce()
if isDebounce then
isDebounce:Destroy()
end
end
end)
do
local old = isDebounce()
if old then old:Destroy() end
end
input.InputBegan:connect(function(InputType)
if InputType.UserInputType == Enum.UserInputType.Keyboard then
local code = InputType.KeyCode
if code == Enum.KeyCode.Q and isDebounce() then
print("Do the thing")
end
end
end)
1 comment
Don't think a local script will work inside a part, it has to be in a player..