I want to make a drinking system for my game, if you get low on thirst then you can go to the lake and a proximity prompt will appear in front of you for you to drink but I don’t want to add lots of parts with proximity prompts how can I do this without making a million little parts?
Is that terrain water or is it just regular meshed water?
Maybe you can try detecting the distance the player is from the lake, then create from the script, the proximity prompt in front of them
It is terrain water, I don’t like the look of mesh water.
How would I do this, then create the proximity prompt in front of them?
This is what I would do as well, here’s an example script.
local run = game:GetService("RunService")
local debris = game:GetService("Debris")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local lakeModel = workspace:WaitForChild("Lake")
run.RenderStepped:Connect(function()
for _, lakePart in ipairs(lakeModel:GetChildren()) do
if lakePart:IsA("BasePart") then
local distance = player:DistanceFromCharacter(lakePart.Position)
if distance <= 10 then --10 studs.
local currentPart = workspace:FindFirstChild(player.Name.."'s Part")
if currentPart then
break
end
local part = Instance.new("Part")
part.Name = player.Name.."'s Part"
part.Anchored = true
part.CanCollide = false
part.CFrame = hrp.CFrame * CFrame.new(0, 0, -3)
local prompt = Instance.new("ProximityPrompt")
prompt.Triggered:Connect(function()
--Do code.
part:Destroy()
end)
prompt.Parent = part
part.Parent = workspace
debris:AddItem(part, 5)
end
end
end
end)
The lake is terrain, does that change anything?
Yeah, that means you’re going to need to use terrain functions.
You’re going to need to read terrain voxels close to the player’s character and then determine if any of those voxels are water blocks.
https://developer.roblox.com/en-us/api-reference/function/Terrain/ReadVoxels
This probably is the best approach but if @V33S is looking for something easier than you could put a part over the lake and detect how far away the player is from that, and pretty much use the Run Service for loops
I used a plugin to create an outline of the lake that’s a part now it’s like this:
(not the best outline)
Is that a single UnionOperation or multiple parts? Either way, that would work.
It is multiple parts should I try and convert it?
No, that should work fine for this.
Should I rename anything in the script you sent?
Group the parts into a single model named “Lake”.
I did and no prompt shows, does it matter where the script is and the script is a LocalScript.
Can you message me a copy of the place/model?
I just sent you a copy of the game file.
You have to parent the prompt to an attachment inside the part I’m pretty sure
Hej
I recommend you cast a ray from mouse/ camera and see if the result is water, then measure the distance between the intersection point and the character primary part.
some psuedocode
if castRay.Terrain == enum.Terrrain.Water and (castRay.Position - CharacterPos).Magnitude <= 10 then
-- show drinking prompt
end