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

This script works in Roblox Studio but not in the actual game?

Asked by 8 years ago

So this script for some reason doesn't work inside the actual game, but if I test it in Roblox Studio it works?

local ShopButton = script.Parent
local Shop = script.Parent.Parent.Frame 
local Close = script.Parent.Parent.Frame.X
local GunGUI1 = Shop.Gun1
local GunGUI2 = Shop.Gun2
local Gun1 = game.ServerStorage:FindFirstChild("Gun1")
local Gun2 = game.ServerStorage:FindFirstChild("Gun2")
Player = game.Players.LocalPlayer

ShopButton.MouseButton1Down:connect(function()
    ShopButton.Visible = false
    Shop.Visible = true
    Close.MouseButton1Down:connect(function()
        ShopButton.Visible = true
        Shop.Visible = false
    end)
end)

GunGUI1.MouseButton1Down:connect(function()
    if Player.Backpack:FindFirstChild("Gun2") and Player.StarterGear:FindFirstChild("Gun2") then
        Player.Backpack.Gun2:Destroy()
        Player.StarterGear.Gun2:Destroy()
    end
    local Gun1C = Gun1:Clone()
    Gun1C.Parent = Player.Backpack
    local Gun1D = Gun1:Clone()
    Gun1D.Parent = Player.StarterGear
    GunGUI1.Visible = false
    GunGUI1.Text = ("Bought")
    GunGUI2.Visible = true
    GunGUI2.Text = ("Gun2")
end)

GunGUI2.MouseButton1Down:connect(function()
    if Player.Backpack:FindFirstChild("Gun1") and Player.StarterGear:FindFirstChild("Gun1") then
        Player.Backpack.Gun1:Destroy()
        Player.StarterGear.Gun1:Destroy()
    end
    local Gun2C = Gun2:Clone()
    Gun2C.Parent = Player.Backpack
    local Gun2D = Gun2:Clone()
    Gun2D.Parent = Player.StarterGear
    GunGUI2.Visible = false
    GunGUI2.Text = ("Bought")
    GunGUI1.Visible = true
    GunGUI1.Text = ("Gun1")
end)


0
Is it a local script Shawnyg 4330 — 8y
0
No it's not. RetroThieff 5 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

If its a local script I would say its correct, theres no problem. If its a normal script then theres a problem at line 8. The variable have : LocalPlayer which means it needs localscript or local before the variable name. Like this for line 8 :

local Player = game.Players.LocalPlayer

its because the normal script doesn't know what is LocalPlayer so we need to put local behind the variable. This code is for the one that doesn't use local script.

For line number 10 untill 17 I recomend you using 'if' and 'else' than making 2 functions. 1 function and if and else is okay.

0
So, if you want to do anything to players like doing game.Players.LocalPlayer, make sure you use local script or put a local on the variable of game.Players.LocalPlayer. krisxxxz 45 — 8y
Ad

Answer this question