-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRBX 15 | fixing local script
51 lines (43 loc) · 1.44 KB
/
RBX 15 | fixing local script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local dog = game.Workspace.storage:FindFirstChild("dog")
local cat = game.Workspace.storage:FindFirstChild("cat")
local amongus = game.Workspace.storage:FindFirstChild("amongus")
local breakable = {dog, cat, amongus}
-- Function to check if the hovered object is in the breakable list
local function isBreakableObject(object)
for _, breakableObject in ipairs(breakable) do
if breakableObject == object then
return true
end
end
return false
end
local function playerInput()
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
local hoveredObject = Mouse.Target
if hoveredObject then
print("Hovered Object: " .. hoveredObject.Name) -- Debugging: Check which object is being hovered
if isBreakableObject(hoveredObject) then
local objectName = hoveredObject.Name
local firstLetter = objectName:sub(1, 1):lower()
if firstLetter == keyPressed.Name:lower() then
print("Destroying object: " .. hoveredObject.Name)
hoveredObject:Destroy()
else
print("Key does not match first letter of object name.")
end
else
print("Hovered object is not in the breakable list.")
end
else
print("No object hovered.")
end
end
end)
end
playerInput()