I am making a blender and I need to know what tool the player is holding. In the local script everything is fine. But when I fire a remote event with the tool as one of the arguments, for some reason the tool disappears. When I try and get an attribute from the tool in a server script, it errors. Here is the local script:
if part:GetAttribute("Type") == "Blender" then
local tool = player.Character:FindFirstChildWichIsA("Tool")
if tool then
game:GetService("Workspace").BlenderActivated:FireServer(tool,part)
end
end
Here is the server script:
local ingredients = {}
game:GetService("Workspace").BlenderActivated.OnServerEvent:Connect(function(player,tool,part)
print("Fired")
if tool then
local status = part:GetAttribute("Status")
if status then
local colour = tool:GetAttribute("Colour")
if colour then
ingredients[tool] = tool:GetAttribute("Colour")
else
error("No colour found for ".. tool.Name.. "; Please add a Color3 attribute named \"Colour\" inside ".. tool.Name)
end
else
error("No status found for requested blender: ".. part.Name)
end
else
warn("No tool found")
end
end)
Sorry there isnât an error as the script checks if there is a tool. The error I would be getting is: Workspace.BlenderServer:7: attempt to index nil with âGetAttributeâ
Iâm assuming this would be line 7? Idk much about attributes but could add print statements for when you retrieve your variables on your server script?
Could it be possible that you have another script thatâs destroying the tool upon activation? Both of your scripts should work fine from what I see, which is strange
The InteractUICloner puts the proximity prompt in every âInteractiveâ part
Here is the whole script if you need it:
wait(1)
for i,part in pairs(workspace:GetDescendants()) do
if part:GetAttribute("Interactive") == true then
local clone = script.ProximityPrompt:Clone()
if part:GetAttribute("Type") == "Fridge" then
clone.ActionText = "Get ".. part:FindFirstChildWhichIsA("Folder"):FindFirstChildWhichIsA("Tool").Name
clone.InteractUI.InteractFrame.ITitle.Text = "Ingredient"
end
if part:GetAttribute("Type") == "Bin" then
clone.ActionText = "Throw away ingredient"
clone.InteractUI.InteractFrame.ITitle.Visible = false
clone.InteractUI.InteractFrame.IngredientsFrame.Visible = false
clone.InteractUI.InteractFrame.Title.Position = UDim2.new(0.177, 0,0.298, 0)
end
if part:GetAttribute("Type") == "Blender" then
clone.ActionText = "Blend"
end
clone.Name = part.Name
clone.Parent = part
--- Interact Script
clone.Triggered:Connect(function(player)
local part = clone.Parent
-- Fridge Script
if part:GetAttribute("Type") == "Fridge" then
local folder = part:FindFirstChildWhichIsA("Folder")
if folder then
local tool = folder:FindFirstChildWhichIsA("Tool")
if tool then
local Clone = tool:Clone()
for index,clonechild in pairs(Clone:GetDescendants())do
if clonechild:IsA("BasePart") then
clonechild.Transparency = 0
clonechild.Anchored = false
end
end
Clone.Parent = player.Character
player.Character:WaitForChild("Humanoid"):EquipTool(Clone)
else
warn("No tool found in folder")
end
else
warn("No tool folder found")
end
end
-- End of Fridge Script
-- Bin Script
if part:GetAttribute("Type") == "Bin" then
game:GetService("Workspace").UnequipTool:FireServer()
print("FIRED")
player.Character:WaitForChild("Humanoid"):UnequipTools()
end
--Counter Script
if part:GetAttribute("Type") == "Counter" then
local tool = part:FindFirstChildWhichIsA("Tool")
local ptool = player.Character:FindFirstChildWhichIsA("Tool")
if tool and ptool == nil then
for index,PART in pairs(tool:GetDescendants()) do
if PART:IsA("BasePart") then
PART.Anchored = false
end
end
tool.Parent = player.Character
player.Character.Humanoid:EquipTool(tool)
game:GetService("Workspace").EquipTool:FireServer(tool)
end
if ptool and not tool then
player.Character.Humanoid:UnequipTools()
game:GetService("Workspace").UnequipTool:FireServer(tool)
ptool.Parent = part
ptool.Handle.CFrame = CFrame.new(part.CFrame.X,part.CFrame.Y+3,part.CFrame.Z)
for i,v in pairs(ptool:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = true
end
if v:IsA("BasePart") then
v.Anchored = true
v.Transparency = 0
end
end
end
end
if part:GetAttribute("Type") == "Blender" then
local tool = player.Character:FindFirstChildWhichIsA("Tool")
if tool then
game:GetService("Workspace").BlenderActivated:FireServer(tool,part)
end
end
--End of Bin Script
end)
--- End of Interact Script
end
end
You can both use ProximityPrompts in Server/LocalScripts, still able to reference the player that way
The only issue that I could possibly see is that you could be referencing the Tool on the Client Side, when you should replicate it to the Server Side instead?