i tried the script and it didn’t work and i got no errors. Am i supposed to put something after the return? I’m sorry if I sound clueless, I’m a beginner scripter lol
Snipping this post, wrong thread.
That’s a bit interesting. I tested it just to be sure it was working, and it did work. Maybe the tool’s named differently? Do note that FindFirstChild
is case-sensitive.
It’s a server script which goes inside the “ClickDetector” instance.
Like this:
where is the script located? My script’s parent is the clickDetector in pizzaBucket
It can be located anywhere that ServerScripts run. Since the Script is under the ClickDetector, it’s as simple as using the Parent
of the Script.
local toolName = 'flour'
local clickDetector = script.Parent; -- Change was made here...
clickDetector.MouseClick:Connect(function(Player)
local Character = Player.Character;
-- In case player has no character.
if (not (Character)) then
return;
end
local Tool = Character:FindFirstChild(toolName);
if (not (Tool) or (Tool.ClassName ~= "Tool")) then
return;
end
Tool:Destroy();
-- Do whatever wanted.
end)
i’ve been wrestling with the problem for awhile and i can’t find an issue.
im sorry for bothering u so much but heres a vid of whats happening. so basically i clicked the block which gives the tool, walked over to the pizzaBucket part and clicked it, but nothing happens. is there something wrong with how the tool is obtained? I can’t come up with anything else
That’s actually an issue with the Tool instance itself. This problem, however, cannot be solved. Unless, you implement your own input detection (via Mouse.Target
), but that’ll be done on the client.
Honestly, I’d recommend you to use ProximityPrompts, since they would work in this case (and they are newer as well).
They aren’t any harder to implement, but they’re more customizable (which probably makes them scary). Here is your functionality but using ProximityPrompts:
local toolName = "flour";
local proximityPrompt = script.Parent; -- Assuming parent is a ProximityPrompt
proximityPrompt.Triggered:Connect(function(Player)
local Character = Player.Character;
-- In case player has no character.
if (not (Character)) then
return;
end
local Tool = Character:FindFirstChild(toolName);
if (not (Tool) or (Tool.ClassName ~= "Tool")) then
return;
end
Tool:Destroy();
-- Do whatever wanted.
end)
it works thank you so much for your time