-
What I Want to Achieve: I want a ball in my game to change the color of any other part it touches. The ball is supposed to move towards the mouse position and then apply a color change upon contact with other parts.
-
Issue: The touch event associated with the ball isn’t working. Despite the ball moving and contacting other parts, no color change occurs, and the expected print statement in the console does not appear…
-
Solutions I’ve Tried:
-
I checked the Roblox Developer Hub for issues similar to mine but didn’t find anything directly applicable.
-
I confirmed that the part names are correct and that the touched parts are indeed Roblox “Part” objects.
-
I have also ensured that there are no issues with the script syntax.
Additional Details:
I suspect the issue might be related to how I’m connecting the touch event or perhaps the conditions under which the event is supposed to trigger. Any insights or suggestions would be greatly appreciated!
local Mouse = game.Players.LocalPlayer:GetMouse()
local ball = game.Workspace.Parth
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local function moveBall()
local mouseHit = Mouse.Hit
local direction = (mouseHit.Position - game.Workspace.CurrentCamera.CFrame.Position).unit
local distance = 30
local targetPosition = game.Workspace.CurrentCamera.CFrame.Position + direction * distance
local tweenInfo = TweenInfo.new(
0.1, -- Time
Enum.EasingStyle.Linear, -- Easing style
Enum.EasingDirection.InOut, -- Easing direction
0, -- Repeat count (zero = no repeat)
false, -- Reverses after repeating
0 -- Delay
)
local tween = TweenService:Create(ball, tweenInfo, {Position = targetPosition})
tween:Play()
end
Mouse.Move:Connect(moveBall)
RunService.Heartbeat:Connect(function()
moveBall()
end)
ball.Touched:Connect(function(otherPart)
if otherPart:IsA("Part") then
otherPart.BrickColor = BrickColor.random()
print("otherPart" .. otherPart.Name)
end
end)