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

Why does this LocalScript not want to spawn in my backpack in ROBLOX Player?

Asked by 7 years ago

So I found this tool with a LocalScript called "Eat" that makes the person get a "Power" (Also a Localscript but inside of the Localscript Eat), and it should spawn into a players backpack as soon as the person eats/consumes/uses the tool.

This script does work on ROBLOX Studio, but not on ROBLOX Player (In-game), can you help me please? If this needs to be more understandable/clearer, please reply in the comments.

I have got all the needed things inside the tool, but it still does not want to work in ROBLOX Player.

Eatscript (LocalScript):

wait()

local tool = script.Parent
local player = game.Players.LocalPlayer

defaultholdingpos = tool.GripPos
eaten = false
equipped = false
cancelled = false
tool.Equipped:connect(function()
    equipped = true
    script.Parent.Activated:connect(function()
        if not eaten then
            cancelled = false
            tool.GripPos = Vector3.new(0.3, -0.5, 1.5)
            tool.Handle.Eat:Play()
            wait(1.4)
            tool.Handle.Eat:Stop()
            if equipped and not cancelled then
                local currentsavedgear = player:FindFirstChild("StarterGear"):GetChildren()
                local hasdf = false
                if #currentsavedgear > 0 then
                    for i = 1, #currentsavedgear do
                        if currentsavedgear[i]:FindFirstChild("DevilFruitAbility") then
                            currentsavedgear[i]:Destroy()
                            hasdf = true
                        end
                    end
                end
                if not hasdf then
                    local dftools = script:GetChildren()
                    for i = 1, #dftools do
                        local df_tag = Instance.new("StringValue")
                        df_tag.Name = "DevilFruitAbility"
                        df_tag.Value = tool.DevilFruitType.Value
                        df_tag.Parent = dftools[i]
                        dftools[i]:Clone().Parent = player:FindFirstChild("Backpack")
                    end
                    tool:Destroy()
                elseif hasdf then
                    if player.Character then
                        if player.Character:FindFirstChild("Humanoid") then
                            player.Character:BreakJoints()
                            player.Character:FindFirstChild("Humanoid").Health = 0
                        end
                    end
                    tool:Destroy()
                end
            end
        end
    end)
end)

tool.Unequipped:connect(function()
    tool.Handle.Eat:Stop()
    cancelled = true
    equipped = false
    if not eaten then
        tool.GripPos = defaultholdingpos
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago

player.Backpack

wait()

local player = game.Players.LocalPlayer
local tool = player.Backpack --- Use player.Backpack instead of script.Parent

defaultholdingpos = tool.GripPos
eaten = false
equipped = false
cancelled = false
tool.Equipped:connect(function()
    equipped = true
    script.Parent.Activated:connect(function()
        if not eaten then
            cancelled = false
            tool.GripPos = Vector3.new(0.3, -0.5, 1.5)
            tool.Handle.Eat:Play()
            wait(1.4)
            tool.Handle.Eat:Stop()
            if equipped and not cancelled then
                local currentsavedgear = player:FindFirstChild("StarterGear"):GetChildren()
                local hasdf = false
                if #currentsavedgear > 0 then
                    for i = 1, #currentsavedgear do
                        if currentsavedgear[i]:FindFirstChild("DevilFruitAbility") then
                            currentsavedgear[i]:Destroy()
                            hasdf = true
                        end
                    end
                end
                if not hasdf then
                    local dftools = script:GetChildren()
                    for i = 1, #dftools do
                        local df_tag = Instance.new("StringValue")
                        df_tag.Name = "DevilFruitAbility"
                        df_tag.Value = tool.DevilFruitType.Value
                        df_tag.Parent = dftools[i]
                        dftools[i]:Clone().Parent = player:FindFirstChild("Backpack")
                    end
                    tool:Destroy()
                elseif hasdf then
                    if player.Character then
                        if player.Character:FindFirstChild("Humanoid") then
                            player.Character:BreakJoints()
                            player.Character:FindFirstChild("Humanoid").Health = 0
                        end
                    end
                    tool:Destroy()
                end
            end
        end
    end)
end)

tool.Unequipped:connect(function()
    tool.Handle.Eat:Stop()
    cancelled = true
    equipped = false
    if not eaten then
        tool.GripPos = defaultholdingpos
    end
end)

I hope this works for you, if it does please accept my answer!

-Arthenix

0
I accept your time trying to fix my problem, but something has gone wrong as I put your script as the Eat Script, the other weld script has acted weird and it does not want to be eaten/consumed/used so nothing happens when I click. ChristianSenpaii 29 — 7y
Ad

Answer this question