Hello!
I have made two scripts, a server and local.
In my serverscript, I scripted it so it detects when the player clicks on a part, then fires a remote event
In my local script, I scripted it so when it recieves the remote, it checks if the player is holding a tool and if so, it destroys the tool. However it does not destroy the tool.
Any solutions?
ServerScript:
local part = script.Parent
local ClickDet = script.Parent.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players")
ClickDet.MouseClick:Connect(function()
ReplicatedStorage.SellRemote:FireClient(player)
end)
Local Script:
local Items = {
["Newspaper"] = 3,
["Rat"] = 2,
["Broken furniture"] = 70,
["Toy"] = 8,
["Bottle"] = 3,
["Shoes"] = 13,
["Monitor"] = 85,
["Clothes"] = 10,
["Scrap Metal"] = 2,
["Cardboard"] = 4,
["Book"] = 4,
["Plastic Container"] = 7,
["Food Scraps"] = 13,
["Hammer"] = 30,
["Can"] = 3,
["Magazines"] = 12,
["Dishes"] = 27,
["Batteries"] = 25,
["Desk"] = 115,
["Chair"] = 43,
["Keyboard"] = 58,
["Lights"] = 43,
["PC"] = 468,
["Fridge"] = 324,
["Microwave"] = 286,
["Paint Brush"] = 11,
["Paint Can"] = 7
}
local player = game.Players.LocalPlayer
local RepStorage = game:GetService("ReplicatedStorage")
local SellRemote = RepStorage.SellRemote
local character = player.Character or player.CharacterAdded:Wait()
character.ChildAdded:Connect(function(newChild)
if not newChild:IsA("Tool") then return end
local value = Items[newChild.Name]
if value then
print(newChild.Name .. " is worth: " .. value)
else
print(newChild.Name .. " not found in table")
end
SellRemote.OnClientEvent:Connect(function() -- The function that I said
if newChild.Equipped then
newChild:Destroy()
end
end)
end)
Also if you’re wondering everything before the SellRemote function works fine.