#Summoning parts while 'C' is being held
41 messages · Page 1 of 1 (latest)
code looks good just create a boolean variable such as
holding = false
then set it to true as the player holds it
use t he function userinput.InputEnded to detect when they let go of the key and set holding to false
if u want to create parts while the key is held u would use while holding == true do
I don't really understand it
let's say we've got the "holding = false" boolean variable but how does the script know when we hold it?
?
its not an actual game function its just how you would check for it
I know
** You are now Level 2! **
so do u want ur script to spawn blocks over and over while u hold c
and then when u release it stops
local lol
local userinput = game:GetService("UserInputService")
local function pressedC(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.C then
lol = Instance.new("Part")
lol.Parent = game.Workspace
lol.Position = Vector3.new(10, 100, 10)
lol.Shape = Enum.PartType.Block
lol.Size = Vector3.new(5, 5, 5)
wait(1)
end
end
end
userinput.InputBegan:Connect(pressedC)
local lol
local userinput = game:GetService("UserInputService")
local holding = false
local function pressedC(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.C then
holding = true
while holding == true do
lol = Instance.new("Part")
lol.Parent = game.Workspace
lol.Position = Vector3.new(10, 100, 10)
lol.Shape = Enum.PartType.Block
lol.Size = Vector3.new(5, 5, 5)
wait(1)
end
end
end
end
userinput.InputBegan:Connect(pressedC)
userinput.InputEnded:Connect(function(Input, istyping)
if Input.KeyCode == Enum.KeyCode.C then
holding = false
end
end)
should work nicely now
so u would just run a check and say while holding == true do
then write t he part spawning code
and then detect when C stops being held and change holding to false so the loop stops
if u get me
ohh I get it now
its good to use things like that
boolean values are great and dont require much extra scripting
well I was actually thinking to set the "pressedC" to nil or something like that
its kinda like a toggle
but I didn't know how
yeah
what do u mean
I thought that to stop the pressedC function I had to set it to false/nil
but I guess I was wrong
u cant set properties of functions
** You are now Level 2! **
well im glad u learned something and g ood luck with ur game