Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

6 comments

0

Just make into a script then Use game.Players.PlayerAdded(Player) to get the Player info.

0

Make sure the script is not disabled. One time this was a problem and i didnt even notice it.

0

wait how can a script be disabled and enabled?

0

through its properties.... do you not have the properties and explorer tab open?

0

I find it hard to make a game without those tabs open.

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.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.