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

Script Only works in Edit mode and not When I publish the game?

Asked by 6 years ago

When I publish the game and try to play it from the site, none of my LocalScripts are working. I tried putting everything inside of a normal script but nothing worked. I think it has something to do with the code itself, but I have no clue where to start. All my code is placed inside of a LocalScript which is in StarterCharacterScripts. Can anyone explain why? Here is my code right now.

--Getting the Camera
game.Players.PlayerAdded:connect(function(player)
    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
end)    


--Local Variables   
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")
local Mouse = player:GetMouse()
local lastTapTime = 0
local clicked = false
local Trail = game.ServerStorage.Trail:Clone()
_G.Energy = 100
local Mouse = player:GetMouse()



--Moving the Humanoid
    --Double Tap
enabled = true
Mouse.KeyDown:connect(function(key)
    if not enabled and clicked then
        return
    end
    if key == "w" and _G.Energy >= 25 then
    enabled = false

    local function onTap()
        if tick() - lastTapTime < 0.2 then
            print("double Click!")
            clicked = true
                --What happends when the user double taps
            player.Character.UpperTorso.Velocity = cam.CFrame.lookVector * Vector3.new(1,0,1) * 400
            Trail.Parent = Char.HumanoidRootPart
            local attachment0 = Instance.new("Attachment", Char.Head)
            attachment0.Name = "TrailAttachment0"
            local attachment1 = Instance.new("Attachment", Char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment1"
            Trail.Attachment0 = attachment0
            Trail.Attachment1 = attachment1
            wait(0.3)
            Trail:Remove()
            _G.Energy = _G.Energy - 25
            wait(0.5)   
            end
        end

        onTap()
        lastTapTime = tick()

        wait(0.5)
        enabled = true
        clicked = false
    end
end)

--Double Jump
enabled = true
Mouse.KeyDown:connect(function(key)
    if not enabled and clicked then
        return
    end
    if key == " " and _G.Energy >= 12.5 then
    enabled = false

    local function onTap()
        if tick() - lastTapTime < 0.2 then
            print("double Click!")
            clicked = true
                --What happends when the user double taps
            player.Character.UpperTorso.Velocity = Vector3.new(0, 100, 0)
            Trail.Parent = Char.HumanoidRootPart
            local attachment0 = Instance.new("Attachment", Char.Head)
            attachment0.Name = "TrailAttachment0"
            local attachment1 = Instance.new("Attachment", Char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment1"
            Trail.Attachment0 = attachment0
            Trail.Attachment1 = attachment1
            wait(0.3)
            Trail:Remove()
            _G.Energy = _G.Energy - 12.5
            wait(1)   
            end
        end

        onTap()
        lastTapTime = tick()

        wait(0.5)
        enabled = true
        clicked = false
    end
end)

--Repleneshing Energy
for i = 1, math.huge do
    wait(0.1)
    print(_G.Energy)
    if _G.Energy < 100 then
        _G.Energy = _G.Energy + 12.5
        print(_G.Energy)
        wait(2)
    end
end
0
hey, could you tell me what error it gives when you test it on a server? Tligtre123 53 — 6y
0
11:04:41 -- ServerStorage is not a valid member of DataModel (next line) Stack Begin (next line) Script 'Workspace.McQuakyDuck.LocalScript', Line 16 (next line) Stack End McQuakyDuck 8 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hey, I have figured it out for you. First, the LocalScript should be in StarterGui. The trail can't be in the ServerStorage if you want to clone it locally. So you need to put the trail in the Workspace. I have improved your script a bit because it gave me some errors. here's the script:

--Getting the Camera
game.Players.PlayerAdded:connect(function(player)
    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
end)    


--Local Variables   
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
game.Workspace:WaitForChild(player.Name)
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")
local Mouse = player:GetMouse()
local lastTapTime = 0
local clicked = false
local Trail = game.Workspace.Trail:Clone() --I have changed it to Workspace because you can't get anything from the ServerStorage locally.
_G.Energy = 100
local Mouse = player:GetMouse()



--Moving the Humanoid
    --Double Tap
enabled = true
Mouse.KeyDown:connect(function(key)
    if not enabled and clicked then
        return
    end
    if key == "w" and _G.Energy >= 25 then
    enabled = false

    local function onTap()
        if tick() - lastTapTime < 0.2 then
            print("double Click!")
            clicked = true
                --What happends when the user double taps
            player.Character.UpperTorso.Velocity = cam.CFrame.lookVector * Vector3.new(1,0,1) * 400
            Trail.Parent = Char.HumanoidRootPart
            local attachment0 = Instance.new("Attachment", Char.Head)
            attachment0.Name = "TrailAttachment0"
            local attachment1 = Instance.new("Attachment", Char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment1"
            Trail.Attachment0 = attachment0
            Trail.Attachment1 = attachment1
            wait(0.3)
            Trail:Remove()
            _G.Energy = _G.Energy - 25
            wait(0.5)   
            end
        end

        onTap()
        lastTapTime = tick()

        wait(0.5)
        enabled = true
        clicked = false
    end
end)

--Double Jump
enabled = true
Mouse.KeyDown:connect(function(key)
    if not enabled and clicked then
        return
    end
    if key == " " and _G.Energy >= 12.5 then
    enabled = false

    local function onTap()
        if tick() - lastTapTime < 0.2 then
            print("double Click!")
            clicked = true
                --What happends when the user double taps
            player.Character.UpperTorso.Velocity = Vector3.new(0, 100, 0)
            Trail.Parent = Char.HumanoidRootPart
            local attachment0 = Instance.new("Attachment", Char.Head)
            attachment0.Name = "TrailAttachment0"
            local attachment1 = Instance.new("Attachment", Char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment1"
            Trail.Attachment0 = attachment0
            Trail.Attachment1 = attachment1
            wait(0.3)
            Trail:Remove()
            _G.Energy = _G.Energy - 12.5
            wait(1)   
            end
        end

        onTap()
        lastTapTime = tick()

        wait(0.5)
        enabled = true
        clicked = false
    end
end)

--Repleneshing Energy
for i = 1, math.huge do
    wait(0.1)
    print(_G.Energy)
    if _G.Energy < 100 then
        _G.Energy = _G.Energy + 12.5
        print(_G.Energy)
        wait(2)
    end
end

If you have any other questions or issues, please tell me.

0
Your a lifesaver! Thanks so much! It works like a charm McQuakyDuck 8 — 6y
0
:D Tligtre123 53 — 6y
Ad

Answer this question