ROBLOX - How would I move the player 8 studs, for 20 miliseconds smoothly (so tweening), in the direction the player is facing? - roblox

How would I move the player 8 studs, for 20 miliseconds smoothly (so tweening), in the direction the player is facing?
script.Parent.Activated:Connect(function()
--[This is because this is a localscript in a tool]
end)

local isGliding = false;
script.Parent.Activated:Connect(function()
isGliding = not isGliding;
local char = script.Parent.Parent; --The tool gets inside of the char when activated
local humanoidRootPart = char:WaitForChild("HumanoidRootPart");
coroutine.wrap(function()
while true do
humanoidRootPart.Positon += humanoidRootPart.LookVector * 8;
wait(0.3)
if isGliding == false then
break;
end
end
end)()
end)
Something like that probably. This should be in a ServerScript under the tool.

Related

ServerScriptService.Size:4: attempt to index nil with 'Humanoid'

Cant figure out what the problem is
while wait(.5) do
local children = game.Players:GetChildren("Humanoid")
for i = 1, #children do
local hum = children[i] .Character.Humanoid
hum.HeadScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyHeightScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyWidthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyDepthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.WalkSpeed = children[i].leaderstats.Points.Value/3.12
hum.JumpPower = children[i].leaderstats.Points.Value
hum.MaxHealth = children[i].leaderstats.Points.Value+25
end
end
was trying to get a simple size script to work.
The attempt to index nil with Humanoid error is telling you that the object that you are trying to grab the Humanoid out of doesn't exist. This line specifically :
local hum = children[i].Character.Humanoid
When a player joins the game, there is an indeterminate amount of time before their character model actually spawns into the world. So between when they join and when their character spawns, the Player.Character property is nil.
Your code does not handle the possibility that the character model is nil, and you are trying to access the humanoid immediately.
A safer approach is not to use a loop, but to observe changes to the leaderstats values and react to those changes. So in your code that creates your leaderstats objects, do something like this :
local Players = game:GetService("Players")
local function updateCharacter(hum : Humanoid, points : number)
local bodyScale = (points / 50) + 1
local walkSpeed = points / 3.12
local jump = points
local health = points + 25
hum.HeadScale.Value = bodyScale
hum.BodyHeightScale.Value = bodyScale
hum.BodyWidthScale.Value = bodyScale
hum.BodyDepthScale.Value = bodyScale
hum.WalkSpeed = walkSpeed
hum.JumpPower = jump
hum.MaxHealth = health
end
Players.PlayerAdded:Connect(function(player)
-- when a player joins the game, give them a leaderstats folder
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
local pointsValue = Instance.new("IntValue", leaderstats)
pointsValue.Name = "Points"
pointsValue.Value = 0 -- or load from dataStores
leaderstatsFolder.Parent = player
-- listen for changes to the points and resize the character
pointsValue.Changed:Connect(function(newValue)
-- escape if the character doesn't exist
local character = player.Character
if character then
updateCharacter(character.Humanoid, newValue)
end
end)
-- when the character model spawns into the world, update it immediately with the player's point size
player.CharacterAdded:Connect(function(character)
updateCharacter(character.Humanoid, pointsValue.Value)
end)
end)

Roblox Functions are running 20+ times

I seem to be having an issue of every time I want to pass a function when an event happens such as a Humanoid.Died() or a BindableEvent it runs the function 20+ times, also adding to an IntegerValue that many times as well. I have tried debounces, BindableEvents, connection:Disconnect(), etc. Is there something I'm doing wrong or missing?
Updated original code:
function module.damageHumanoid(attacker, player, humanoid, damage)
local connection
local debounce = false
connection = humanoid.Died:Connect(function()
if not debounce then
debounce = true
connection:Disconnect()
module.onDeath(player)
end
end)
if player:FindFirstChild("damage") == nil then
newFolder = Instance.new("Folder")
newFolder.Name = "damage"
newFolder.Parent = player
end
if newFolder:FindFirstChild(tostring(attacker)) == nil then
record = Instance.new("IntValue")
record.Name = tostring(attacker)
record.Parent = newFolder
end
if record.Value >= 100 then -- sanity check
else
record.Value = record.Value + damage
end
return humanoid:TakeDamage(damage)
end
Which triggers this code:
function module.onDeath(player)
if player:FindFirstChild("damage") ~= nil then
local folder = player:WaitForChild("damage")
local contents = folder:GetChildren()
for i,v in pairs(contents) do
local item = folder[tostring(v)]
damages[item.Name] = item.Value
end
end
local debounce = false
if not debounce then
debounce = true
module.handleKill(damages)
end
end
This is the sword script's function:
function Blow(Hit)
if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
return
end
local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
if not RightArm then
return
end
local RightGrip = RightArm:FindFirstChild("RightGrip")
if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
return
end
local character = Hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health == 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and player == Player then
return
end
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
module.damageHumanoid(plur, player, humanoid, Damage)
end
So I guess the way I was trying to use debounce isn't correct anymore. I referred to the Roblox documentation and found this: https://create.roblox.com/docs/scripting/scripts/debounce
If anyone would like to know what ended up working for me here it is:
humanoid.Died:Connect(function()
if not humanoid:GetAttribute("Killed") then
humanoid:SetAttribute("Killed", true)
module.onDeath(player)
task.wait(10)
humanoid:SetAttribute("Killed", true)
end
end)

When I mine a rock in my game (Click it 10 times) it mines and gives 100 coins. However if someone else does it it gives it to me? Can anyone h3lp?

So when I click it 10 times it mines however it only give coins to me when someone else mines it. I have no clue really what to do so i need help. Ok so here is the script:
game.Players.PlayerAdded:Connect(function(player)
script.Parent:Clone()
local money = player:WaitForChild("leaderstats").Money
script.Parent.ClickDetector.MouseClick:Connect(function()
local billboard = script.Parent.BillboardGui
print(health)
health = health - 1
billboard.Enabled = true
billboard.TextLabel.Text = health
if health == 0 then
local clickdetector = script.Parent.ClickDetector
billboard.Enabled = false
money.Value = money.Value + 100
script.Parent.ClickDetector.Parent = nil
script.Parent.Union.Transparency = 1
script.Parent.Union.CanCollide = false
wait(5)
clickdetector.Parent = script.Parent
script.Parent.Union.Transparency = 0
script.Parent.Union.CanCollide = true
health = 10
end
end)
end)
The problem is that you need to make sure the player variable matches the player that clicked it.
script.Parent.ClickDetector.MouseClick:Connect(function()
should be:
script.Parent.ClickDetector.MouseClick:Connect(function(clicker)
and use an if statement:
if clicker == player then
--code that gives points
end
Also when you clone the parent it clones the script so that may cause bugs.

My Roblox Script doesn't change the model based on time (Roblox)

I'm working on an automatic Street Light that is supposed to change based on the time. Here is the code:
--------------------------------------------
-----------Street Light Script!-------------
-----------Made by multiplemark-------------
--------------------------------------------
local ControlledByGameTime = true -- Setting to true makes it so that the lights
activate only during the selected time.
local TurnLightsOnAt = 20 * 60 -- Turns lights on at 8 P.M. by default.
local TurnLightsOffAt = 8 * 60 -- Turns lights off at 8 A.M. by default.
local Lights = script.Parent.PointLight.Enabled
local LightBlock = script.Parent
if ControlledByGameTime == true then
while true do
local CurrentTime = game.Lighting:GetMinutesAfterMidnight()
if CurrentTime >= TurnLightsOffAt then
Lights = false
LightBlock.Material = "SmoothPlastic"
LightBlock.Brick = 163,162,165
end
if CurrentTime >= TurnLightsOnAt then
Lights = true
LightBlock.Material = "Neon"
LightBlock.Brick = 255,255,0
end
end
else
Lights = true
LightBlock.Material = "Neon"
LightBlock.Color = 255,255,0
end
What it is supposed to do is check for the time, and if it meets the requirements defined, change the material and color of a model, and also enabling/disabling PointLight.
I think the issue is your if statements. You're evaluating if it's after 8 pm after you evaluate if it's 8 am. Since 8 pm (or 20 in 24-hour format) comes after 8 am (or 8 24-hour format), if a value if greater than 8 pm, it's also greater than 8 am.
What you could do is just have an equals statement instead of a greater than. So something like:
if (time==TURNOFFLIGHTS)
turnofflights ();
else if (time==TURNONLIGHTS)
turnonlights ();
That way, it only turns off the lights at the specific moment that night begins and only turns them on the moment day begins.

is there a touch and hold event in Corona sdk, If not then how to do that

is there a touch and hold event in Corona sdk, If not then how to do that. for example. i want to increase the radius of a circle while holding anywhere on the screen, and without moving. how to do that.
'
thanx
Try (as I know you can't change radius so I use xScale and yScale to increase circle)
local circle = display.newCircle( display.contentCenterX, display.contentCenterY, 50 )
step = 0.02
local holding = false
local function enterFrameListener()
if holding then
-- Holding button
circle.xScale = circle.xScale + step
circle.yScale = circle.yScale + step
else
-- Not holding
-- Code here
end
end
local function touchHandler( event )
if event.phase == "began" then
Runtime:addEventListener( "enterFrame", enterFrameListener )
holding = true
elseif event.phase == "ended" or event.phase == "moved" then
holding = false
Runtime:removeEventListener( "enterFrame", enterFrameListener )
end
return true
end
Runtime:addEventListener( "touch", touchHandler )
The code borrow from post from stackoverflow.com.