What I am trying to achieve is to make a part turn from transparency 0 to 0.1 when clicked, but
I want click detector to work when a player has a tool in their inventory.
local ToolA = script.Parent.Parent.Parent.StarterPack.ToolA
local Orbz = game:GetService("Workspace"):WaitForChild("Orbz")
local object = script.Parent
local clickdetector = script.Parent.ClickDetector
clickdetector.MouseClick:Connect(function()
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
if player.Backpack:FindFirstChild(ToolA) then
Orbz.Transparency = 0.1
elseif player.Character:FindFirstChild(ToolA) and player.Character:FindFirstChild(ToolA):IsA("Tool") then
Orbz.Transparency = 0.1
end
end
end)
Something like this in the script should work and act like a normal one:
local Mouse = player:GetMouse()
tool.Activated:Connect(function() --check if the tool is active and then next line that it is equipped
if tool.Equipped then
if Mouse.Target and Mouse.Target:FindFirstChild("ClickDetector") then -- checks for click detector
if (tool.Handle.Position - Mouse.Target.Position).Magnitude <= Mouse.Target.ClickDetector.MaxActivationDistance then --respects the max distance of it
--Code here!
end
end
end
end)
Basically .Activated is always called and not the click detector itself.
That’s a much better idea. I know how to make code that makes proximity prompt cause an event, but I’m not sure how to make the proximity prompt activate when a player has a tool in their inventory.
local tool = player.BackPack:FindFirstChildWhichIsA("Tool") or char:FindFirstChildWhichIsA("Tool")
if tool.Name == "ToolA" then
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.Transparency = 0.1
end)
You need to refrence the player and character first, put it after this line
so
local ToolA = script.Parent.Parent.Parent.StarterPack.ToolA
local Orbz = game:GetService("Workspace"):WaitForChild("Orbz")
local object = script.Parent
local clickdetector = script.Parent.ClickDetector
clickdetector.MouseClick:Connect(function(player)
if player then
local char = player.Character
local tool = player.BackPack:FindFirstChildWhichIsA("Tool") or char:FindFirstChildWhichIsA("Tool")
if tool and tool.Name == "ToolA" then
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.Transparency = 0.1
end
end
end)
local ToolA = script.Parent.Parent.Parent.StarterPack.ToolA
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
end
local char = player.Character or player.CharacterAdded:Wait()
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
end
local tool = player.BackPack:FindFirstChildWhichIsA("Tool") or char:FindFirstChildWhichIsA("Tool")
if tool.Name == "ToolA" then
end
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.Transparency = 0.1
end)
i cant tell what im reading, can you format that in studio rq?
(To Format, Open The Script > Press Ctrl + A > Right Click > Press Format • As Document)
local ToolA = script.Parent.Parent.Parent.StarterPack.ToolA
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
end
local char = player.Character or player.CharacterAdded:Wait()
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
end
local tool = player.BackPack:FindFirstChildWhichIsA("Tool") or char:FindFirstChildWhichIsA("Tool")
if tool.Name == "ToolA" then
end
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.Transparency = 0.1
end)
local ToolA = script.Parent.Parent.Parent.StarterPack.ToolA
local Orbz = game:GetService("Workspace"):WaitForChild("Orbz")
local object = script.Parent
local clickdetector = script.Parent.ClickDetector
clickdetector.MouseClick:Connect(function()
end)
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
if player then
end
local char = player.Character
local tool = player.BackPack:FindFirstChildWhichIsA("Tool") or char:FindFirstChildWhichIsA("Tool")
if tool and tool.Name == "ToolA" then
end
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.Transparency = 0.1
end)
local player = game:GetService("Players"):GetPlayerFromCharacter(ToolA)
Clickdetectors automatically return the player, so you can use clickdetector.MouseClick:Connect(function(player) instead. I’ve edited the script again, try it now
Also you should try and solve these problems yourself a little, we’re not supposed to give you scripts, you’re supposed to look for past posts and event documents and trying them instead of asking here right away, Scripting Support isn’t a script request, it’s a place to learn and improve