Hey there,
So I want to make a classic tycoon game that features classic gui’s and appearances, I however stumbled upon a problem.
In the “classic” hub the cursor can click parts that contain clickdetectors.
My cursor however lacks that feature.
My script:
local resetPlayerGui = false
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local char = nil
local diskOrigin = script:WaitForChild("Disk")
local disk
local distance = 55
local enabled = true
local cursor = script.Parent:WaitForChild("Cursor")
cursor.Visible = true
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local pr = nil
local newDisk = diskOrigin:Clone()
if not resetPlayerGui then
if game:GetService("Workspace").CurrentCamera:FindFirstChild("Disk") then
game:GetService("Workspace").CurrentCamera.Disk:Destroy()
end
end
newDisk.Parent = game:GetService("Workspace").CurrentCamera
disk = newDisk
local keys = {}
while char == nil do
local t = wait(1/30)
char = player.Character
end
if resetPlayerGui then
function defineChar()
while char == nil do
local t = wait(1/30)
char = player.Character
end
end
defineChar()
player.CharacterAdded:connect(function() char = nil defineChar() end)
end
userInputService.MouseIconEnabled = false
function findTool()
if char then
local children = char:GetChildren()
for i = 1, #children do
if children[i]:IsA("Tool") then
return true
end
end
return false
end
end
mouse.KeyDown:connect(function(key)
keys[key:lower()] = true
if key:byte() == 17 then
keys["w"] = true
end
if key:byte() == 20 then
keys["a"] = true
end
if key:byte() == 18 then
keys["s"] = true
end
if key:byte() == 19 then
keys["d"] = true
end
end)
mouse.KeyUp:connect(function(key)
keys[key:lower()] = false
if key:byte() == 17 then
keys["w"] = false
end
if key:byte() == 20 then
keys["a"] = false
end
if key:byte() == 18 then
keys["s"] = false
end
if key:byte() == 19 then
keys["d"] = false
end
end)
mouse.Button1Down:connect(function()
if enabled then
local pos = mouse.Hit.p
if pr then
pr:Destroy()
end
pr = diskOrigin:Clone()
pr.Parent = game:GetService("Workspace").CurrentCamera
pr.CFrame = CFrame.new(pos)
if char and char:FindFirstChild("Humanoid") then
char.Humanoid:MoveTo(pr.Position, pr)
end
end
end)
runService.RenderStepped:connect(function()
cursor.Position = UDim2.new(0, mouse.X - cursor.AbsoluteSize.X/2, 0, mouse.Y - cursor.AbsoluteSize.Y/2)
if findTool() then
enabled = false
cursor.Image = ""
userInputService.MouseIconEnabled = true
else
mouse.TargetFilter = disk
cursor.Size = UDim2.new(0, 128, 0, 128)
userInputService.MouseIconEnabled = false
if enabled then
cursor.Image = "rbxassetid://172802980"
else
cursor.Image = "rbxassetid://167166957"
end
end
disk.Parent = enabled and game:GetService("Workspace").CurrentCamera or game:GetService("Lighting")
if keys["w"] or keys["a"] or keys["s"] or keys["d"] then
if pr then
pr:Destroy()
end
end
if pr then
if char and char:FindFirstChild("Torso") then
local mag = (char.Torso.Position - pr.Position).magnitude
if math.floor(mag) <= 3 then
pr:Destroy()
end
end
end
end)
while true do
disk.CFrame = CFrame.new(mouse.Hit.p)
if char and char:FindFirstChild("Torso") then
if (char.Torso.CFrame.p - mouse.Hit.p).magnitude > distance then
enabled = false
else
if not findTool() then
enabled = true
end
end
end
local t = wait(1/60)
end
thank you for helping in advance.