Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my script work after the game is published?

Here is my code.

what i don't understand is i even took out everything except closing the gui, and even that didn't work. so i am scrambling my brains here!

script.Parent.MouseButton1Click:connect(function()

--local m = Instance.new("Message") --m.Text = ("This is a Test") --wait(3) --m:remove()

local equipping = script.Parent.Parent.Equipping.Value local storage = game.ServerStorage local player = game.Players.LocalPlayer local plr = player.Name

player.CameraMode = "LockFirstPerson"

for a, b in pairs (storage:GetChildren()) do if b.ClassName == "Tool" and b.Name == tostring(equipping) then local newEquip = b:Clone() newEquip.Parent = player.Character end end

script.Parent.Parent.Enabled = false script.Parent.Modal = false

end)

The basis is it will equip the item, leave and lock you in first person view with that tool equipped.

I have tried both a local and normal script just to test and neither are working as in studio. not sure what if my mind is just missing something or what not. Need some fresh eyes.

Thanks in advance.

3 comments

0

You're using deprecated code, and using Strings in place of Enumerations. And please use code blocks.

0

You're also wrapping things in () that is not okay.

0

The hell you on about ._.

1 answer

✓ Accepted answer
-- LocalScript
script.Parent.MouseButton1Click:Connect(function() -- use :Connect
    local plr = game:GetService("Players").LocalPlayer
    local screen = Instance.new("ScreenGui",plr.PlayerGui) -- Messages are deprecated.
    screen.Name = "MessageGUI" 
    local msg = Instance.new("TextLabel",screen)
    msg.Name = "Message"
    msg.Size = UDim2.new(0, 600, 0, 400)
    msg.Position = UDim2.new(0.5, -300, 0.5, -200)
    msg.Text = "This is a test" -- See i didn't say ' ("This is a test") '?
    wait(3)
    screen:Destroy() -- :remove() is deprecated
    
    local storage = game:GetService"ReplicatedStorage" -- Server Storage is inaccessible from local scripts.
    plr.CameraMode = Enum.CameraMode.LockFirstPerson -- Don't say "LockFirstPerson"
    for a, b in pairs(storage:GetChildren()) do
        if b:IsA"BackpackItem" then-- a tool
            local newEquip = b:Clone() -- your code made no sense tbh so sorry
            newEquip.Parent = plr.Backpack
            plr.Character.Humanoid:EquipTool(plr.Backpack[newEquip.Name])
            -- done
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.