- What do you want to achieve? Keep it simple and clear!
When my camera mouse from first person view is pointing towards a model, I want it to show a proximity prompt.
- What is the issue? Include screenshots / videos if possible!
The proximity prompt does not show when the player is too close, or is pointing at the model from certain angles. Heres a video demonstrating the issue:
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried messing with ALL of the properties of the ProximityPrompt. Nothing worked.
Below is a portion of client-sided code on how a proximity prompt is revealed. The proximity prompt is cloned from ReplicatedStorage and placed as a child of every model spawned in workspace. The client sided code allows for a player to aim at a model via raycasting, which then should reveal the bounding box (this works perfectly), and the proximity prompt which that model has (not working perfectly).
Client-Sided Code:
local lastHitModel = nil
local blacklistedPart = nil
local function performRaycast()
local origin = camera.CFrame.Position
local direction = camera.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -1))
local ray = Ray.new(origin, direction * 20)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {lockers, player.Character, baseplate}
local raycastResult = workspace:Raycast(origin, direction * 20, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local hitModel = hitPart.Parent
if hitModel and hitModel:IsA("Model") and hitModel:FindFirstChild("ProximityPrompt") then
local selectionBox = hitModel:FindFirstChild("SelectionBox")
local proximityPrompt = hitModel.ProximityPrompt
if selectionBox and selectionBox:IsA("SelectionBox") then
selectionBox.Visible = true
proximityPrompt.Enabled = true
end
if lastHitModel and lastHitModel ~= hitModel and lastHitModel:FindFirstChild("SelectionBox") then
lastHitModel.SelectionBox.Visible = false
lastHitModel.ProximityPrompt.Enabled = false
end
lastHitModel = hitModel
end
else
if lastHitModel and lastHitModel:FindFirstChild("SelectionBox") then
lastHitModel.SelectionBox.Visible = false
lastHitModel.ProximityPrompt.Enabled = false
end
lastHitModel = nil
end
end
claimingPhase.OnClientEvent:Connect(function()
game:GetService("RunService").Heartbeat:Connect(performRaycast)
end)
Here is also the image of the hierarchy of an average model spawning into the map:
Here is the properties I have for the ProimityPrompt: