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

Hello! I wanted to know why my script works in studio when i test it, but doesn't in game.

Asked by 10 years ago

Its very weird, I have tried to fix it with some problems it might have caused it in the scripts... If you need the scripts, here they are:

 script.Parent.MouseButton1Down:connect(function()

        plr = game.Players.LocalPlayer
if script.Parent.Parent.Parent.Parent.Parent.Primary.Value == "Gun" then
for i, v in pairs (plr.Backpack:GetChildren())do
        if v:IsA("Tool") and v.Primary.Value == true and v.Primary ~= nil and v.Name == "Gun" then
                                 v:Destroy()
print("Destroyed")
elseif v:IsA("Tool") and v.Primary.Value == true and v.Primary ~= nil and v.Name == "Gun" and v.Parent == game.Players.LocalPlayer.Character then
     v:Destroy()
print("Destroyed from Character")

end end end 
for i, v in pairs(game.Players.LocalPlayer.PlayerGui.inventory:GetChildren()) do
                      if not found1 then
                        if v.ClassName == "StringValue" and v.Value == "" then
                                  v.Value = "Gun"
                                     found1 = true
end end end

if script.Parent.Parent.Parent.Parent.Parent.Primary.Value == "Bow" then          
for i, v in pairs (plr.Backpack:GetChildren())do
        if v:IsA("Tool") and v.Primary.Value == true and v.Primary ~= nil and v.Name == "Bow" then
                                 v:Destroy()
print("Destroyed")
elseif v:IsA("Tool") and v.Primary.Value == true and v.Primary ~= nil and v.Name == "Bow" and v.Parent == game.Players.LocalPlayer.Character then
     v:Destroy()
print("Destroyed from Character")
end end end 
 for i, v in pairs(game.Players.LocalPlayer.PlayerGui.inventory:GetChildren()) do
                      if not found1 then
                        if v.ClassName == "StringValue" and v.Value == "" then
                                  v.Value = "Bow"
                                     found1 = true
end end end
script.Parent.Parent.Parent.Image = ""
script.Parent.Parent.Parent.Primary.Value = false    
script.Parent.Parent.Parent.dead.Value = 0  
script.Parent.Parent.Visible = false   
   found1 = false           
end)

and second one:

local found1 = false

script.Parent.MouseButton1Click:connect(function()
    if game.ReplicatedStorage.Folder:FindFirstChild("Gun") then
    c = game.ReplicatedStorage.Folder.Gun:Clone()
    end
    if game.ReplicatedStorage.Folder:FindFirstChild("Bow") then
    b = game.ReplicatedStorage.Folder.Bow:Clone()
    end
    plr = game.Players.LocalPlayer
if script.Parent.Parent.Parent.Parent.Parent.Primary.Value == "Gun" then
    for i, v in pairs (game.Players.LocalPlayer.Backpack:GetChildren())do
        if not found1 then
    if v:IsA("Tool") then
        if v.Primary.Value == true then 
        v:Destroy()
        print("Destroyed again...")
                c.Parent = workspace
c:MoveTo(plr.Character.Torso.Position + Vector3.new(math.random(1,3),0,math.random(1,3)))
found1 = true
script.Parent.Parent.Parent.Image = ""
script.Parent.Parent.Parent.Parent.Parent.Primary.Value = ""
script.Parent.Parent.Parent.dead.Value = 0
script.Parent.Parent.Visible = false
end end end end end
if script.Parent.Parent.Parent.Parent.Parent.Primary.Value == "Bow" then
    for i, v in pairs (game.Players.LocalPlayer.Backpack:GetChildren())do
        if not found1 then
    if v:IsA("Tool") and v.Name == "Bow" and v.Primary.Value == true then
        if v.Primary.Value == true then 
        v:Destroy()
        print("Destroyed again...")
        b.Parent = workspace
b:MoveTo(plr.Character.Torso.Position + Vector3.new(math.random(1,3),0,math.random(1,3)))
found1 = true
script.Parent.Parent.Parent.Image = ""
script.Parent.Parent.Parent.Parent.Parent.Primary.Value = ""
script.Parent.Parent.Parent.dead.Value = 0
script.Parent.Parent.Visible = false
found1 = false
        elseif  v:IsA("Tool") and v.Name == "Bow" and v.Primary.Value == true and v.Parent == game.Players.LocalPlayer.Character then
            v:Destroy()
        b.Parent = workspace
b:MoveTo(plr.Character.Torso.Position + Vector3.new(math.random(1,3),0,math.random(1,3)))
found1 = true
script.Parent.Parent.Parent.Image = ""
script.Parent.Parent.Parent.Parent.Parent.Primary.Value = ""
script.Parent.Parent.Parent.dead.Value = 0
script.Parent.Parent.Visible = false
found1 = false
end end end end end end)

2 answers

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago

The answer could be that it is not a local script since it works on studios, try it and tell me.

0
alright deputychicken 226 — 10y
0
Thanks so much <3 deputychicken 226 — 10y
0
Your Welcome. :P HexC3D 830 — 10y
Ad
Log in to vote
0
Answered by
Kratos232 105
10 years ago

I don't think I could fix a problem like this without the actual model, which i'm just going to assume is a GUI. It could be that you used normal Scripts, instead of LocalScripts. Or maybe it's an actual scripting error, I don;t really know. To be honest, I just can;t be bothered reading that whole script...

Well, I hope this helped, which I doubt it did...

  • Kratos232

Answer this question