#How could i make so the item drops to the ground?

1 messages · Page 1 of 1 (latest)

crude orbit
#

I want to make it so the previous item drops to the ground when i pick up a new one but i dont know how, can someone help? (same for when you press g)

queen spruce
# crude orbit

you could just have physics apply to the dropped tool for a second (by unachoring it, then reanchoring it after a few seconds (to save on physics calculations)), yet that could cause some unwanted physics issues

crude orbit
queen spruce
crude orbit
#

oh ye, forgot that lol, let me try that

#

how can i check if the player is holding an item

queen spruce
crude orbit
#

did that

visual pumiceBOT
#

studio** You are now Level 6! **studio

queen spruce
#

Set it to nil if the player drops a weapon (without picking one up), and just the if currentTool when he picks something up

#

if that check passes, then you know that he has a tool that he first has to drop

crude orbit
#

okay

queen spruce
#

(I would also just make a function for dropping tools, and fire it both when the player "drops" the tool, and when he picks a tool up while already having one)

#

Just makes it easier to write it all

crude orbit
#

@queen spruce

queen spruce
#

I would also maybe change over currentTool to an instance instead of a string, will help with processing

crude orbit
#

okay

#

i got an error

PlayerScripts.Item:55: Expected identifier when parsing expression, got ')'  -  Studio - Item:55
queen spruce
#

show line 55

crude orbit
#

its line 60

queen spruce
#

one of your if statements has no end

crude orbit
#

i tried to add an end, nothing changed

queen spruce
#

it could also be multiple ones, just format the code and see where you're missing ends

crude orbit
#

okay

#

im not missing any now and it still says that

queen spruce
#

You're most likely still missing one (or have an extra one)

crude orbit
#

i cant find it tho

queen spruce
#

send the entire code

crude orbit
#

ok

#
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local inputservice = game:GetService('UserInputService')
local tweenService = game:GetService('TweenService')
local player = game.Players.LocalPlayer
local currentTool = nil
local camera = workspace.CurrentCamera

UIS.InputChanged:Connect(function(input)
    if mouse.Target then
        if mouse.Target:FindFirstChild("Show") then
            player.PlayerGui.Info.Enabled = true
            player.PlayerGui.Info.Adornee = mouse.Target
            player.PlayerGui.Info.Titel.Text = mouse.Target.Name
            player.PlayerGui.Info.Disc.Text = mouse.Target.Disc.Text
            player.PlayerGui.Info.Pickup.Text = mouse.Target.Pickup.Text
        end
    end
            
            
    local info = TweenInfo.new(
    0,
    Enum.EasingStyle.Linear
)

local debounce = false

inputservice.InputBegan:Connect(function(input, IS)
    if IS == true then return end

                if input.KeyCode == Enum.KeyCode.E and mouse.Target then
            mouse.Target:FindFirstChild("Show").Parent.CanCollide = false
            currentTool = mouse.Target.Name
            
            if currentTool then
                player.PlayerGui.InGameGUI.ItemCtrl.ItemFull.Visible = true
                wait(2)
                player.PlayerGui.InGameGUI.ItemCtrl.ItemFull.Visible = false
            end
            
            else

            while task.wait() do
                for _, v in pairs(workspace.Tools:GetDescendants()) do
                    if v.Name == currentTool then
                        local targetCFrame = camera.CFrame * CFrame.new(2.5,-1,-2) * CFrame.Angles(math.rad(-90), math.rad(0), 0)
                        local tween = tweenService:Create(v, info, {CFrame = targetCFrame})
                        tween:Play()
                    end
                end
            end
        end```
#
                if input.KeyCode == Enum.KeyCode.G  and debounce then
                    if currentTool then
                        for _, v in pairs(workspace.Tools:GetDescendants()) do
                            if v.Name == currentTool then
                                v:FindFirstChild("Show").Parent.CanCollide = true
                                v:FindFirstChild("Show").Parent.Anchored = false
                                currentTool = nil
        end
    end
end)

        
        else
            player.PlayerGui.Info.Enabled = false
            player.PlayerGui.Info.Adornee = nil
            player.PlayerGui.Info.Titel.Text = ""
            player.PlayerGui.Info.Disc.Text = ""
            player.PlayerGui.Info.Pickup.Text = ""
end)```
queen spruce
#

line 10/29 don't close in time

crude orbit
#

huh

#

wdym by dont close in time

queen spruce
#

basically, there is no "end" after it

crude orbit
#

okay

#

where should there be an end in that place

#

it just gives me more errors when i add one

#

@queen spruce

queen spruce
crude orbit
#

alright, thank you

queen spruce
#
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local inputservice = game:GetService('UserInputService')
local tweenService = game:GetService('TweenService')
local player = game.Players.LocalPlayer
local currentTool = nil
local camera = workspace.CurrentCamera
local debounce = false

UIS.InputChanged:Connect(function(input)
    if mouse.Target then
        if mouse.Target:FindFirstChild("Show") then
            player.PlayerGui.Info.Enabled = true
            player.PlayerGui.Info.Adornee = mouse.Target
            player.PlayerGui.Info.Titel.Text = mouse.Target.Name
            player.PlayerGui.Info.Disc.Text = mouse.Target.Disc.Text
            player.PlayerGui.Info.Pickup.Text = mouse.Target.Pickup.Text
        end
    end
end)

local info = TweenInfo.new(
    0,
    Enum.EasingStyle.Linear
)


inputservice.InputBegan:Connect(function(input, IS)
    if IS == true then return end

    if input.KeyCode == Enum.KeyCode.E and mouse.Target then
        mouse.Target:FindFirstChild("Show").Parent.CanCollide = false
        currentTool = mouse.Target.Name

        if currentTool then
            player.PlayerGui.InGameGUI.ItemCtrl.ItemFull.Visible = true
            wait(2)
            player.PlayerGui.InGameGUI.ItemCtrl.ItemFull.Visible = false
        end
    else
        while task.wait() do
            for _, v in pairs(workspace.Tools:GetDescendants()) do
                if v.Name == currentTool then
                    local targetCFrame = camera.CFrame * CFrame.new(2.5,-1,-2) * CFrame.Angles(math.rad(-90), math.rad(0), 0)
                    local tween = tweenService:Create(v, info, {CFrame = targetCFrame})
                    tween:Play()
                end
            end
        end
    end                
    
#
if input.KeyCode == Enum.KeyCode.G  and debounce then
        if currentTool then
            for _, v in pairs(workspace.Tools:GetDescendants()) do
                if v.Name == currentTool then
                    v:FindFirstChild("Show").Parent.CanCollide = true
                    v:FindFirstChild("Show").Parent.Anchored = false
                    currentTool = nil
                end
            end
        else --I'm not even sure what this else belongs to.. You'll probably have to move this around, this is why guard clauses are an import life skill 
            player.PlayerGui.Info.Enabled = false
            player.PlayerGui.Info.Adornee = nil
            player.PlayerGui.Info.Titel.Text = ""
            player.PlayerGui.Info.Disc.Text = ""
            player.PlayerGui.Info.Pickup.Text = ""
        end
    end
end)
#

@crude orbit , just make sure to read that comment

crude orbit
#

ye

#

i did

#

ty

#

the error is gone now, but nothing is happening when i press g

#

is it because of the tween?

crude orbit
queen spruce
#

As stated in the comment, this is why guardclauses are important, as I've no clue which else belongs to which if