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

Script doesn't work if placed into a LocalScript? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I made this Script, and when I realized it had to be a LocalScript and I moved it to a LocalScript, it stopped working. As a Script, it works the way I want it to, but when in a LocalScript, it doesn't even run the script (It didn't even print() something I told it to print in the first line of my script, and the rest doesn't get run either.) Both scripts were in Workspace when I tested them. The script is here:

print("deb") --My attemp at debugging
wait(3)

local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local ContextActionService = game:GetService('ContextActionService')
local eActivated = false
local bombReload = tick()
local currentBomb = nil
local playerTorsoPos = player.Character.LowerTorso.Position

function round(num) 
    if num >= 0 then return math.floor(num+.5) 
    else return math.ceil(num-.5) end
end

function roundTo5(num) --These snap the object to a grid
    num = round(num)
    num = num / 5
    num = round(num)
    num = num * 5
    return num
end


local function makeBomb() --Creates the object when E is pressed
    currentBomb = Instance.new("Part", Workspace)
    currentBomb.Name = player.Name
    currentBomb.Shape = "Ball"
    currentBomb.Anchored = true
    currentBomb.CanCollide = false
    currentBomb.Size = Vector3.new(4, 4, 4)
    currentBomb.Material = "Metal"
    currentBomb.BrickColor = BrickColor.new("Dark blue")
    currentBomb.CFrame = CFrame.new(roundTo5(playerTorsoPos.X), 3, roundTo5(playerTorsoPos.Z))
    wait(3)

end



local function onE(actionName, inputState) --Finds out when E is pressed
    if inputState == Enum.UserInputState.Begin then
        eActivated = true       
    elseif inputState == Enum.UserInputState.End then
        eActivated = false
    end
end

local function onUpdate() --Calls funcion to create object
        print("deb") --Debug for if this loop is running
    if player.Character and player.Character:FindFirstChild('Humanoid') then
        if eActivated and (tick() - bombReload) > 1 then        
            print("You just pressed E") --Debug if it gets the signal that E was presssed
            --print(tick()-bombReload)
            bombReload = tick()
            makeBomb()
        end
    end
end

RunService:BindToRenderStep('Control', Enum.RenderPriority.Input.Value, onUpdate)
ContextActionService:BindAction('Jump', onE, true, 'e', Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
0
Just make into a script then Use game.Players.PlayerAdded(Player) to get the Player info. KenUSM 53 — 6y
0
Make sure the script is not disabled. One time this was a problem and i didnt even notice it. hiimgoodpack 2009 — 6y
0
wait how can a script be disabled and enabled? RiskoZoSlovenska 378 — 6y
0
through its properties.... do you not have the properties and explorer tab open? hiimgoodpack 2009 — 6y
View all comments (2 more)
0
I find it hard to make a game without those tabs open. hiimgoodpack 2009 — 6y
0
Yes I do have those tabs open, but I didn't see the Disabled option. Its not the problem anyway, as its enabled. Also, I'm new to Lua, and how do you use game.Players.PlayerAdded(Player) at all? Because I have no idea. I think that putting this script into a LocalScript is the best way to do it. RiskoZoSlovenska 378 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

So, my problem was, that I had the LocalScript in the Workspace. After moving it to StarterPlayerScripts, it started working.

Ad

Answer this question