The script is suppose to highlight a part when your mouse is over it. Theres 2 parts where this happens and once you highlight your mouse over one part, you can’t do it to the other part.
Its returning with an Infinite yield and when I use workspace rather than WaitForChild it just gives me an error.
The parts are far enough away from each other to where it’ll disappear off the workspace and come back when the player is close enough.
local players = game:GetService("Players")
local plr = players.LocalPlayer
local runService = game:GetService("RunService")
local Highlight = game.Workspace.PartScart.Highlight
local mouse = plr:GetMouse()
function ishovering(part)
if mouse.Target == game.Workspace:WaitForChild("PartScart") then
print("hovering")
Highlight.Enabled = true
return true
else
Highlight.Enabled = false
return false
end
end
runService.Heartbeat:Connect(function()
local h = ishovering(game.Workspace:WaitForChild("PartScart"))
end)
Script#2
local players = game:GetService("Players")
local plr = players.LocalPlayer
local runService = game:GetService("RunService")
local Highlight = game:GetService("Workspace"):WaitForChild("ScartPart2").Highlight
local mouse = plr:GetMouse()
function ishovering(part)
if mouse.Target == game:GetService("Workspace"):WaitForChild("ScartPart2") then
print("hovering")
Highlight.Enabled = true
return true
else
Highlight.Enabled = false
return false
end
end
runService.Heartbeat:Connect(function()
local h = ishovering(game:GetService("Workspace"):WaitForChild("ScartPart2"))
end)
Here is a quick code i made on mobile, just make sure you use your custom tag name in the code and assign the tag to your highlight holder. Put in StarterPlayer
This code wont make u have to disable streamingmode and is more efficient and made for scalability.
— Service
local RunService = game:GetService(”RunService”)
local Players = game:GetService(”Players”)
— Player
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
— Temp
local LastTarget
RunService.PreRender:Connect(function()
if Mouse.Target and Mouse.Target:HasTag(”MyHighlightTag” and LastTarget ~= Mouse.Target then
local Highlight = Mouse.Target:FindFirstChildOfClass(”Highlight)
if Highlight then
LastTarget = Mouse.Target
Highlight.Enabled = true
end
else
LastTarget.Highlight.Enabled = false
end
end)
its not the workspace. It just cant find the ScartPart2 in
local Highlight = game:GetService("Workspace"):WaitForChild("ScartPart2").Highlight
Do you have StreamingEnabled on?
If so then you should make sure to put your part into a model and then set the ModelStreamingMode on the model to Persistent so its loaded all the time.