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

My stereo tool works in test mode but not in an actual game server?

Asked by 7 years ago

Here is the script in the stereo itself:

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local tool = script.Parent

local X = 1

tool.Equipped:connect(function(mouse)
    script.Parent.Handle.CanCollide = false
    mouse.Button1Down:connect(function()
        if X == 1 then
            player.PlayerGui.Stereo.TextButton.Visible = true
            X = 0
        else
            player.PlayerGui.Stereo.TextButton.Visible = false
            X = 1
        end
    end)
end)

tool.Unequipped:connect(function(mouse)
    script.Parent.Handle.CanCollide = true
    player.PlayerGui.Stereo.TextButton.Visible = false
    player.PlayerGui.Stereo.TextButton.Sound.Playing = false
    X = 1
end)

This is in the gui:

local player = game.Players.LocalPlayer

local X = 1

local Y = 1

script.Parent.MouseButton1Click:connect(function()
    if X == 1 then
        X = 0
        script.Parent.Parent.ID.Visible = true
        script.Parent.Parent.Confirm.Visible = true
        script.Parent.Parent.Choices.Visible = true
    else
        script.Parent.Parent.ID.Visible = false
        script.Parent.Parent.Confirm.Visible = false
        script.Parent.Parent.Choices.Visible = false
        script.Parent.Parent.RussianNatinalAnthem.Visible = false
        script.Parent.Parent.Yee.Visible = false
        script.Parent.Parent.Pizza.Visible = false
        X = 1
    end
end)

script.Parent.Parent.Confirm.MouseButton1Click:connect(function()
    if X == 0 then
        script.Parent.Parent.ID.Visible = false
        script.Parent.Parent.Confirm.Visible = false
        script.Parent.Parent.Choices.Visible = false
        script.Parent.Parent.RussianNatinalAnthem.Visible = false
        script.Parent.Parent.Yee.Visible = false
        script.Parent.Parent.Pizza.Visible = false
        local ID = script.Parent.Parent.ID.Text
        script.Parent.Sound.SoundId = ("rbxassetid://"..ID)
        script.Parent.Sound.Playing = true
        X = 1
    end
end)

script.Parent.Parent.Choices.MouseButton1Click:connect(function()
    if Y == 1 then
        script.Parent.Parent.RussianNatinalAnthem.Visible = true
        wait(0.1)
        script.Parent.Parent.Yee.Visible = true
        wait(0.1)
        script.Parent.Parent.Pizza.Visible = true
        Y = 0
    else
        script.Parent.Parent.RussianNatinalAnthem.Visible = false
        wait(0.1)
        script.Parent.Parent.Yee.Visible = false
        wait(0.1)
        script.Parent.Parent.Pizza.Visible = false
        Y = 1
    end
end)

script.Parent.Parent.RussianNatinalAnthem.MouseButton1Click:connect(function()
    script.Parent.Parent.ID.Text = 720623106
end)

script.Parent.Parent.Pizza.MouseButton1Click:connect(function()
    script.Parent.Parent.ID.Text = 248372723
end)

script.Parent.Parent.Yee.MouseButton1Click:connect(function()
    script.Parent.Parent.ID.Text = 636843817
end)



local mouse = player:GetMouse()

while wait() do
    if script.Parent.Parent.TextButton.Visible == false then
        script.Parent.Parent.ID.Visible = false
        script.Parent.Parent.Confirm.Visible = false
        script.Parent.Parent.Choices.Visible = false
        script.Parent.Parent.RussianNatinalAnthem.Visible = false
        script.Parent.Parent.Yee.Visible = false
        script.Parent.Parent.Pizza.Visible = false
        X = 1
    end
end

For more information about the scripts and so please ask!

Thanks for answers!

0
Maybe add a :WaitForChild() at the beginning of your script? I don't know if that helps, but give it a shot. TickTockTheory 106 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

I have seen many people with this problem and it's actually an easy fix. First off, when defining variables, if it is a GUI Item (TextLabels, TextButton, Frames) then you should always (When defining them) add a WaitForChild("Name") function. For example:

script.Parent.Parent.Choices.Visible = false

You might want to change it to

script.Parent.Parent:WaitForChild("Choices").Visible = false

Also, you used a lot of script.Parent.Parent so I suggest you make it a variable.

So I will fix the script I hope you understand, In the fixes I will tell you the parts I fixed so you understand:

Here is the script in the stereo itself (Fixed):

local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse() -- Changed to game.Players.LocalPlayer because it will make the system easier to find the Mouse
local tool = script.Parent
local X = 1

tool.Equipped:connect(function(mouse)
    tool.Handle.CanCollide = false -- Don't have to say script.Parent theres a reason you have the local tool variable
    mouse.Button1Down:connect(function()
        if X == 1 then
            player.PlayerGui.Stereo:WaitForChild("TextButton").Visible = true -- Like I said you need to add a WaitForChild("Name") function
            X = 0
        else
            player.PlayerGui.Stereo:WaitForChild("TextButton").Visible = false -- WaitForChild("Name")
            X = 1
        end
    end)
end)

tool.Unequipped:connect(function(mouse)
    tool.Handle.CanCollide = true -- Once again you have the tool variable
    player.PlayerGui.Stereo:WaitForChild("TextButton").Visible = false -- WaitForChild("Name")
    player.PlayerGui.Stereo:WaitForChild("TextButton"):WaitForChild("Sound").Playing = false -- WaitForChild("Name")
    X = 1
end)

Now for the second script, there are also lot's of stuff you can change so it might work

This is in the gui (Fixed):

local player = game.Players.LocalPlayer
local X = 1 -- I would change X and Y because they are both = 1 but i guess You don't need too
local Y = 1
local button = script.Parent -- added this variable so that scripting is easier and it will be easier for the computer itself to find
local Frame = script.Parent.Parent -- added because by looking at the script you probably have this frame
button.MouseButton1Click:connect(function() 
    if X == 1 then
        X = 0
        Frame:WaitForChild("ID").Visible = true -- Added WaitForChild and used the new frame variable
        Frame:WaitForChild("Confirm").Visible = true -- Added WaitForChild and used the new frame variable
        Frame;WaitForChild("Choices").Visible = true -- Added WaitForChild and used the new frame variable
    else
        Frame:WaitForChild("ID").Visible = false -- Added WaitForChild and used the new frame variable
        Frame:WaitForChild("Confirm").Visible = false -- Added WaitForChild and used the new frame variable
        Frame:WaitForChild("Choices").Visible = false -- Added WaitForChild and used the new frame variable
        Frame:WaitForChild("RussianNatinalAnthem").Visible = false -- Added WaitForChild and used the new frame variable
        Frame;WaitForChild('Yee').Visible = false -- Added WaitForChild and used the new frame variable
        Frame:WaitForChild("Pizza").Visible = false
        X = 1
    end
end)


-- These functions I highly recommend you to make a local script and put it inside the button. Some new variables are added 
local Button = script.Parent.Parent

Button:WaitForChild("Confirm").MouseButton1Click:connect(function()
    if X == 0 then
        Button:WaitForChild("ID").Visible = false -- Added WaitForChild and used the new Button Variable
        Button:WaitForChild("Confirm").Visible = false -- You know what I did to the rest ._.
    Button:WaitForChild("Choices").Visible = false
        Button:WaitForChild("RussianNatinalAnthem").Visible = false
        Button:WaitForChild("Yee").Visible = false
        Button:WaitForChild("Pizza").Visible = false
        local ID = script.Parent.Parent:WaitForChild("ID").Text -- Added WaitForChild
        script.Parent.Sound.SoundId = ("rbxassetid://"..ID)
        script.Parent.Sound.Playing = true
        X = 1
    end
end)

Button:WaitForChild("Choices").MouseButton1Click:connect(function()
    if Y == 1 then
        Button:WaitForChild("RussianNatinalAnthem").Visible = true
        wait(0.3) -- 0.1 is a bit to fast, let's make it 0.3 so the system has more time to function
        script.Parent.Parent.Yee.Visible = true
        wait(0.3) -- 0.1 is a bit to fast, let's make it 0.3 so the system has more time to function
        Button:WaitForChild("Pizza").Visible = true
        Y = 0
    else
        Button:WaitForChild("RussianNatinalAnthem").Visible = false
        wait(0.3) -- 0.1 is a bit to fast, let's make it 0.3 so the system has more time to function
        Button:WaitForChidl("Yee").Visible = false -- changed to WaitForChild
        wait(0.3) -- 0.1 is a bit to fast, let's make it 0.3 so the system has more time to function
        Button:WaitForChild("Pizza").Visible = false 
        Y = 1
    end
end)

Button:WaitForChild("RussianNatinalAnthem").MouseButton1Click:connect(function()
    Button:WaitForChild("ID").Text = "720623106" --Added WaitForChild and when showing a text always use "Your Text" marks
end)

Button:WaitForChild("Pizza").MouseButton1Click:connect(function()
    Button:WaitForChidl("ID").Text = "248372723"  --Added WaitForChild and when showing a text always use "Your Text" marks
end)

script.Parent.Parent.Yee.MouseButton1Click:connect(function()
 WaitForChild("ID").Text = "636843817"  --Added WaitForChild and when showing a text always use "Your Text" marks
end)


local mouse = Game.Players.LocalPlayer:GetMouse() -- easier to define
while wait() do -- I changed all to WaitForChild
    if Button:WaitForChild("TextButton").Visible == false then
        Button:WaitForChild("ID").Visible = false
        Button:WaitForChild("Confirm").Visible = false
        Button:WaitForChild("Choices").Visible = false
        Button:WaitForChild("RussianNatinalAnthem").Visible = false
        Button:WaitForChild("Yee").Visible = false
        Button:WaitForChild("Pizza").Visible = false
        X = 1
    end
end

That is ALL the fixed, took me half a hour. If it doesn't work open up OutPut in studio and tell me why, post the error and line

If it works please accept answer for rep points but other wise I hope you learned something and I hope it fixed your problems!

BlackOrange3343

Ad
Log in to vote
0
Answered by 7 years ago

This normally occurs either when the script is running when the game hasn't fully loaded or due to Filtered Enabled being on. So I would check both. check the in-game output by pressing Ctrl+F9 or on a mac Cmd+fn+F9

0
I put 'wait(10)' in the beginning of the scripts but now my stereo giver doesn't work... Neodosa 7 — 7y
0
Also... Theres NOTHING in the server log except "Player 93819868" added and "Datamodel Loading http://assetgame.roblox.com/asset/?id=718930372" Neodosa 7 — 7y
0
Well then I reccomend you try using an added event such as PlayerAdded() and CharacterAdded() LastApollo 76 — 7y
Log in to vote
0
Answered by 7 years ago

Adding a wait doesn´t necessarily mean it will work. You should, instead, run the code when a player has been added. There are multiple ways of doing this but here is a really simple, self explanatory method.

local Players = game:GetService("Players")

function onPlayerAdded(player)
     print(player.Name .. " has entered the game")
end

--When a player joins, call the onPlayerAdded function
Players.PlayerAdded:connect(onPlayerAdded)

Answer this question