Heya guys,
I was wondering how to make a script that when a proximity prompt is triggered, it runs code, but only if a player is holding a tool.
I did try, but I found when said item is held, it goes into the player model in the workspace and is no longer in the backpack.
Here is what I got:
local TweenService = game:GetService("TweenService")
local ProximityPrompt = script.Parent.Trigger.ProximityPrompt
local billboardGui = script.Parent.BillboardGui
local colourGoal = {BackgroundColor3 = Color3.new(0.611765, 0, 0.0117647)}
local colourTween = TweenService:Create(billboardGui.Frame.Frame, TweenInfo.new(3), colourGoal)
ProximityPrompt.Triggered:Connect(function(player)
local patty = player.Backpack.Patty
if player.Backpack.Patty.Equipped == true then
billboardGui.Enabled = true
billboardGui.Frame.Frame:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 5)
wait(6)
colourTween:Play()
end
end)
local currentTool = player.Character:FindFirstChilsWhichIsA("Tool")
if not tool then
-- Player is not holding tool. Rejection logic.
end
if currentTool.Name == "SpecificToolName" then
-- Handling logic
end
|| Also, I would suggest disabling the prompt when tool is unequipped and re enabling it when it is equipped. ||
Hi, I am not sure how to access the player model in the workspace from the player, I did try it with player.name and then under workspace find the name, but it didn’t work. Do you know how I can do it?
Since you have the ProximityPrompt along with player args you could just do player.Character inside the .Triggered event
--for demonstration only, don't replace it with this
local proximity_dir = script.Parent
proximity_dir.Triggered:Connect(function(player)
local char = player.Character --player is defined as specific who triggered it
end
Hi, this worked thank you for this!
(however I have a slight issue I stated at the end of this message)
Here is the fixed script just in case anyone else needs the answer:
local TweenService = game:GetService("TweenService")
local ProximityPrompt = script.Parent.Trigger.ProximityPrompt
local billboardGui = script.Parent.BillboardGui
local colourGoal = {BackgroundColor3 = Color3.new(0.611765, 0, 0.0117647)}
local colourTween = TweenService:Create(billboardGui.Frame.Frame, TweenInfo.new(3), colourGoal)
ProximityPrompt.Triggered:Connect(function(player)
local char = player.Character
if char:WaitForChild("Patty") then
billboardGui.Enabled = true
billboardGui.Frame.Frame:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 5)
wait(6)
colourTween:Play()
end
end)
(slight issue, when triggered and not holding it, it doesnt do anything like intended, but without triggering again, just when you hold it, it seems to run that code…)