generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: keysdown function

Previous Thread :: Next Thread 
clanky4 is not online. clanky4
Joined: 21 Oct 2009
Total Posts: 389
03 Jul 2013 09:01 AM
I am trying to make a tool that when the player presses the f button the tool's parent is set to nil.

However when the player presses f nothing happens. It is a local script.


function keysDown(key)
if key == "f" then
script.Parent.Parent = nil

end
end
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
03 Jul 2013 09:03 AM
How long is the complete script? Can you paste it?
Report Abuse
clanky4 is not online. clanky4
Joined: 21 Oct 2009
Total Posts: 389
03 Jul 2013 09:11 AM
It a basic rocket launcher script that has been edited slightly to include ammo. The bit of script that is having issues has --new stuff around it. Line 109 to line 115.

Again the rest of the script it working just fine.

local Tool = script.Parent
local Launcher = Tool.Handle

local Rocket = Instance.new("Part")
Rocket.Locked = true
Rocket.BackSurface = 3
Rocket.BottomSurface = 3
Rocket.FrontSurface = 3
Rocket.LeftSurface = 3
Rocket.RightSurface = 3
Rocket.TopSurface = 3
Rocket.Size = Vector3.new(1, 2.5, 1)
Rocket.BrickColor = BrickColor.new(23)
Rocket.FormFactor = 3


--[[local rocketMesh = Instance.new("SpecialMesh")
rocketMesh.MeshId = "http://www.roblox.com/asset/?id=31601976"
rocketMesh.TextureId = "http://www.roblox.com/asset/?id=31601599"
rocketMesh.Parent = Rocket]]

local debris = game:GetService("Debris")

local swooshSound
local explosionSound

local vCharacter
local vPlayer

function blow(hit, missile)
if missile == nil then return end
if swooshSound then swooshSound:stop() end
explosion = Instance.new("Explosion")
explosion.Position = missile.Position
-- find instigator tag
local creator = missile:FindFirstChild("creator")
explosion.Hit:connect(function(part, distance) onPlayerBlownUp(part, distance, creator) end)
explosion.Parent = game.Workspace
if explosionSound then explosionSound:Play() end
wait(.1)
if missile then missile:Remove() end
end

function onPlayerBlownUp(part, distance, creator)
if part.Name == "Head" or part.Name == "Torso" then
local humanoid = part.Parent.Humanoid
tagHumanoid(humanoid, creator)
end
end

function tagHumanoid(humanoid, creator)
-- tag does not need to expire if all explosions lethal
if creator ~= nil then
local new_tag = creator:clone()
new_tag.Parent = humanoid
end
end

function fire(vTarget)
local vCharacter = Tool.Parent
local vHandle = Tool:findFirstChild("Handle")
if vHandle == nil then
print("Handle not found")
return
end
local direction = vTarget - vHandle.Position
direction = computeDirection(direction)
local missile = Rocket:clone()
local pos = vHandle.Position + (direction * 10.0)
missile.CFrame = CFrame.new(pos, pos + direction) * CFrame.Angles(math.pi/2, 0, 0)

local creator_tag = Instance.new("ObjectValue")

local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)

if vPlayer == nil then
print("Player not found")
else
if (vPlayer.Neutral == false) then -- nice touch
missile.BrickColor = vPlayer.TeamColor
end
end

local floatForce = Instance.new("BodyForce")
floatForce.force = Vector3.new(0, missile:GetMass() * 196.1, 0.0)
floatForce.Parent = missile

missile.Velocity = direction * 100.0

creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = missile

missile.Parent = game.Workspace

if swooshSound then swooshSound:Play() end

missile.Touched:connect(function(hit) blow(hit, missile) end)

debris:AddItem(missile, 100.0)
end

function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

--new stuff
function keysDown(key)
if key == "f" then
script.Parent.Parent = nil
end
end
--new stuff

Tool.Enabled = true
function onActivated()
if not Tool.Enabled then
return
end

local playersearch = game.Players:GetChildren()

for i= 1, #playersearch do
if playersearch[i].Name == script.Parent.Parent.Name then
local playersname = playersearch[i]
local weaponspecs = playersname.Backpack:FindFirstChild(script.Parent.weapontype.Value):FindFirstChild(script.Parent.weapontype.weaponslot.Value)

if weaponspecs.clip.Value <= 0 and weaponspecs.ammo.Value >= weaponspecs.clip.clipsize.Value then

Tool.Enabled = false
weaponspecs.ammo.Value = weaponspecs.ammo.Value - weaponspecs.clip.clipsize.Value
weaponspecs.clip.Value = weaponspecs.clip.Value + weaponspecs.clip.clipsize.Value

wait(5)
Tool.Enabled = true
elseif weaponspecs.clip.Value <= 0 and weaponspecs.ammo.Value < weaponspecs.clip.clipsize.Value and weaponspecs.ammo.Value ~= 0 then

Tool.Enabled = false
weaponspecs.clip.Value = weaponspecs.clip.Value + weaponspecs.ammo.Value
weaponspecs.ammo.Value = weaponspecs.ammo.Value - weaponspecs.ammo.Value
wait(5)
Tool.Enabled = true

elseif weaponspecs.clip.Value > 0 then

Tool.Enabled = false

local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

swooshSound = Launcher:FindFirstChild("Swoosh")
explosionSound = Launcher:FindFirstChild("Explosion")

local targetPos = humanoid.TargetPoint

fire(targetPos)
weaponspecs.clip.Value = weaponspecs.clip.Value - 1
wait(5)

if weaponspecs.clip.Value <= 0 and weaponspecs.ammo.Value >= weaponspecs.clip.clipsize.Value then

weaponspecs.ammo.Value = weaponspecs.ammo.Value - weaponspecs.clip.clipsize.Value
weaponspecs.clip.Value = weaponspecs.clip.Value + weaponspecs.clip.clipsize.Value
Tool.Enabled = true

elseif weaponspecs.clip.Value <= 0 and weaponspecs.ammo.Value < weaponspecs.clip.clipsize.Value and weaponspecs.ammo.Value ~= 0 then

weaponspecs.clip.Value = weaponspecs.clip.Value + weaponspecs.ammo.Value
weaponspecs.ammo.Value = weaponspecs.ammo.Value - weaponspecs.ammo.Value
Tool.Enabled = true

else
Tool.Enabled = true

end
end end end end

script.Parent.Activated:connect(onActivated)
Report Abuse
guusjo15 is not online. guusjo15
Joined: 29 Sep 2012
Total Posts: 133
03 Jul 2013 09:34 AM
We must now regret having asked for the full script.
Report Abuse
cheatmaster18 is not online. cheatmaster18
Joined: 29 Oct 2010
Total Posts: 1871
03 Jul 2013 09:47 AM
Any output?
Report Abuse
clanky4 is not online. clanky4
Joined: 21 Oct 2009
Total Posts: 389
03 Jul 2013 10:22 AM
The weapon shoots and reloads properly the only thing it wont do it set the tool to nil when the player presses f.

I tried putting in a few prints to see exactly what it wasn't doing but since it is a local script it has no output.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
03 Jul 2013 10:25 AM
Is it throwing any errors? It seems you haven't set up a way to call the function.
Report Abuse
clanky4 is not online. clanky4
Joined: 21 Oct 2009
Total Posts: 389
03 Jul 2013 10:28 AM
I assumed that:

function keysDown(key)

would be the way in which it checked if the player is pressing any keys and:

if key == "f" then

would be the check for if the key was f.

Is there some specific fucntion for keysdown? The wiki explained it very poorly.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
03 Jul 2013 10:33 AM
Replace the function with:

script.Parent.Equipped:connect(function(Key)
Key.KeyDown:connect(function(Key)
if Key == "f" then
script.Parent.Parent = nil
end
end)
end)

I'm assuming that the script is placed directly under a tool.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image