Basically, i want to make a robbery game that mix up My pet rock and prison genre on roblox, like you make roberry you earn cash and from cash you can buy stuff, you will be able to steal etc…
What i want in my client side script is to have a highlight system that when you click, it will make your character walk to the hit position. After some testing i realised the click detector wasnt firing.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local target
local runService = game:GetService("RunService")
local imputservice = game:GetService("UserInputService")
local hihlightables = {
workspace["Robbery Machine"]
}
--require(player.PlayerScripts.PlayerModule.ControlModule):Disable()
--workspace.Camera.CameraType = Enum.CameraType.Scriptable
local function gethighlights()
local higlights = {}
for _, i in workspace:GetDescendants() do
if i:IsA("Highlight") then
table.insert(higlights,i)
end
end
return higlights
end
local function getclickdetectors()
local clickdetectors = {}
for _, i in workspace:GetDescendants() do
if i:IsA("ClickDetector") then
table.insert(clickdetectors,i)
end
end
return clickdetectors
end
local object
local lastobject
local clickconnection
runService.RenderStepped:Connect(function()
for _, child in gethighlights() do
child:Destroy()
end
if clickconnection then
clickconnection:Disconnect()
end
for _, child in getclickdetectors() do
child:Destroy()
end
target = mouse.Target
if target then
if table.find(hihlightables,target) then
object = target
end
if table.find(hihlightables,target.Parent) then
object = target.Parent
end
end
if object then
local highlight = Instance.new("Highlight")
highlight.Parent = object
highlight.Adornee = object
highlight.FillTransparency = 1
highlight.OutlineTransparency = 0
highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
local clickdetector = Instance.new("ClickDetector")
clickdetector.Parent = object
clickconnection = clickdetector.MouseClick:Connect(function()
if object == lastobject then
print("clicked")
object = nil
end
end)
end
lastobject = object
object = nil
end)