Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Not able to remove a players tool after interacting with ProximityPrompt?

Asked by 3 years ago
Edited 3 years ago

I have so far tried this, which is located in a group model, in a script:

local itemName = "FirstRoom"
local player = game:GetService("Players").LocalPlayer

script.Parent.UnlockDoor1.Triggered:Connect(function()
    if player.Character and player.Character:FindFirstChild(itemName) and player.Character[itemName]:IsA("Tool") then
        player.Character[itemName]:Destroy()
    end
    end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

First thing if you destroy the tool on the client, the server will still think it's there so use RemoteEvents. But since you're using ProximityPrompt we can get the PlayerObject with the ProximityPrompt.Triggered event because it comes with a parameter which is the player that triggered the ProximityPrompt.

Putting tools in StarterPack will replicate all of the service's contents into the client's Backpack.

ServerScript:

--[[
First, define your ProximityPrompt. 
Next, you want to connect the Triggered event to a function(The triggered Event comes with a parameter which is the player that triggered it).
In the function, there is a variable and an if statement which will see if the player has the tool in the character or the backpack,
If they do then it will destroy it.
]]

local proximityPrompt = workspace.Part.ProximityPrompt
local itemName = "FirstRoom"

proximityPrompt.Triggered:Connect(function(playerThatTriggered)
    local tool = playerThatTriggered.Backpack:FindFirstChild(itemName)

    if tool or playerThatTriggered.Character:FindFirstChild(itemName) then

        tool:Destroy()
    end
end)

I'd put this script in ServerScriptService

0
I re-edited it because if the player was holding the tool which will move the tool from the Backpack into the Character model MarkedTomato 810 — 3y
0
Still somehow doesn't appear to destroy the tool, I get "ServerScriptService.ServerScriptDoor1:16: attempt to index nil with 'Destroy'". A little more insight would be that, whenever the player holds the tool, the proximityPrompt becomes enabled, and once you interact with it, the 'tool' is 'used' Officer_Striker 2 — 3y
0
Cheers, just moved the tool from StarterPack to somewhere else so I could pick it up during the game, and then rewrote an entire script for it with a few of your lines. Officer_Striker 2 — 3y
Ad

Answer this question