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

Can anyone explain why my code works on the Studio test run, but doesn't work on the real game?

Asked by 6 years ago
Edited 6 years ago

I have a pretty big script here, and it took me forever to make it. Its 2 scripts split up by LocalScripts. I've tested it in Studio, and it works perfectly. Yet, when i play the actual game, it start making up problems. Here is the code now. Its 1 local script in StarterGui

local UIS = game:GetService('UserInputService')
local pressing
local Energy = 90
local player = game.Players.LocalPlayer
local character = player.Character
local PrettyColor = false
if not player or not character.Parent then
    character = player.CharacterAdded:wait()
end
local torso = character.LowerTorso
local fire = Instance.new("Fire")
fire.Parent = torso
fire.Enabled = false
fire.Heat = 6
fire.Size = 6


UIS.InputBegan:connect(function(inputObject, gameProcessedEvent)
    if not gameProcessedEvent then
        if inputObject.KeyCode == Enum.KeyCode.C then
            pressing = true
            while pressing do
                wait(.2)
                Energy = Energy + 1
                    fire.Enabled = true
                    if PrettyColor == false then
                    fire.Color = Color3.new(255,255,255)
                    fire.SecondaryColor = Color3.new(255,255,255)
                    PrettyColor = true
                    end
                    _G.GetEnergy(Energy)
            print('Charging....')

            end
        end
        fire.Enabled = false
    end
end)

UIS.InputEnded:connect(function(inputObject, gameProcessedEvent)
    if not gameProcessedEvent then
        if inputObject.KeyCode == Enum.KeyCode.C then
            pressing = false
            print('u stopped pressing :)')
            fire.Enabled = false
        end
    end
end)
0
I used to have it in 2 scripts, and they communicated by _G. But the GameRun decided it doesnt work anymore. Said i was trying to call a nil value of a function. So, i merge the scripts together (i wish they stayed seperate) and now its saying that LowerTorso isnt a valid member of Model (line 10) User#19492 0 — 6y
0
As far as I know, the CharacterAdded:Wait() event never seems to work in-game. This is what I'd do: "repeat wait () until plr.Character and plr.Character:FindFirstChild("HumanoidRootPart")" Mayk728 855 — 6y
0
Are you sure that will work 100%? User#19492 0 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Do you have filtering enabled turned on, if so... (I can't seem to comment - probably because of my low reputation so I can only say it here):

I've read about such situations before and have experienced it first hand and and I can likely tell you that this is as in studio, the local scripts act as normal scripts. So if you have filtering enabled, since local scripts can't communicate with the server, anything that changes the server should not work in the real game.

In your script:

local fire = Instance.new("Fire")
fire.Parent = torso
fire.Enabled = false
fire.Heat = 6
fire.Size = 6

These things are the ones that has to be created by the server so that everyone see it, thus, it is most probably this that causes the local script to stop working. Note: Only if you have filtering enabled.

Solution: Personally, I would create a remote event to communicate with a server script to do it.

0
that isnt a problem. Seems to register that just fine. However, it is saying the character doesnt exist. User#19492 0 — 6y
Ad

Answer this question