I was writing a thing that lets you press e on a part to add it to your inventory. It was in a local script, so I had the client mail over mouse.Target with a Remote Event. However, mouse.Target is a boolean. I’m confused because the local script used mouse.Target just fine to pick up objects. Here is my two scripts, and output error
Local Script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService") --we will use this service for something later
local target
local down
local UserInputService = game:GetService("UserInputService")
local EKey = Enum.KeyCode.E
local addremote = game.ReplicatedStorage:WaitForChild("AddToPlayer")
local function EKeyDown()
return UserInputService:IsKeyDown(EKey)
end
local function Input(input, gameProcessedEvent)
if not EKeyDown() then return else
if mouse.Target ~= nil and mouse.Target.Locked == false and mouse.Target.Anchored == false then
addremote:FireServer(mouse.Target)
end
end
end
UserInputService.InputBegan:Connect(Input)
mouse.Button1Down:connect(function()
if mouse.Target ~= nil and mouse.Target.Locked == false then
mouse.Icon = "rbxasset://textures/GunCursor.png"
target = mouse.Target
mouse.TargetFilter = target
down = true
local gyro = Instance.new("BodyGyro") --adding the forces
gyro.Name = "Gyro"
gyro.Parent = target
gyro.MaxTorque = Vector3.new(500000, 500000, 500000)
local force = Instance.new("BodyPosition")
force.Name = "Force"
force.Parent = target
force.MaxForce = Vector3.new(10000, 10000, 10000) --you may wanna modify this a bit, since it effect if you can move an object or wrong depending on its weight/mass (in other words, the force might not be strong enough)
end
end)
game:GetService("RunService").RenderStepped:Connect(function() --replaced the move event with renderstepped because it works better in some cases, renderstepped is an event that fires every frame, basically super fast, look it up it is important!
if down == true and target ~= nil then
target.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 20)
end
end)
mouse.Button1Up:connect(function()
if target then --of course we wanna remove the forces after the dragging, first check if there was even a target
if target:FindFirstChild("Gyro") or target:FindFirstChild("Force") then --check if there was a force
mouse.Icon = ""
target.Gyro:Destroy() --DESTROY!!!!
target.Force:Destroy()
end
end
down = false
mouse.TargetFilter = nil
target = nil
end)
Server Script
local remote = game.ReplicatedStorage:WaitForChild("AddToPlayer")
local tool = game.ReplicatedStorage:WaitForChild("Tool")
remote.OnServerEvent:Connect(function(player, part)
local char = player.Character or player.CharacterAdded:Wait()
local newtool = tool:Clone()
local newpart = part:Clone().Parent == game.ServerStorage
part.Name = "Handle"
part.Parent = newtool
newtool.Parent = char
newpart.Transparency = 1
newpart.CanCollide = false
newpart.Anchored = true
newpart.Parent = newtool
end)
Output Error
ServerScriptService.Main:10: attempt to index boolean with 'Transparency'
Help would be appreciated!!