camerasubject not working on roblox studio - roblox

i have problems with the camerasubject in
roblox studio.
This is my code.
game.Players.PlayerAdded:Connect(function(player)
wait(2)
workspace.Camera.CameraSubject = workspace.Camera1["Almost dead person"].Humanoid
workspace.Camera.CameraType = Enum.CameraType.Scriptable
wait(4)
workspace.Camera.CameraSubject = workspace.Camera2["Almost dead person"].Humanoid
wait(1)
workspace.Camera.CameraType = Enum.CameraType.Fixed
workspace.Camera:Destroy()
end)

It seems to me that the problem would be on line 3 and line 6, it seems to be caused by you having a ["object name"], you cant continue the selection after a object spaced name bracket, my fix will be renaming Almost dead person to Almost_dead_person and update the name in the code.

Your CameraSubject needs to be its own separate child of Camera since there is no . to add another child.

Related

why can't I get a checkpoint to flash with a script?

I am trying really hard to start with a simple skeleton on Roblox Studio, and then change one of the checkpoints (or all of them) so that they flash.
I thought to do that by using a script that I saw online that changes the transparency from 1 to 0 and back every 1 second.
So I tried this (I added this to all Checkpoints quite consistently in the same way):
and this (for this one I just added the part at the bottom):
but whenever I played in the Studio to test it I always got static checkpoints:
It is either the script is not running, or transparency is not the right way to go or what?
The "Checkpoints" folder has many objects in it that are called "Checkpoint". If you want to flash a particular one from its child script, you could do this instead:
while (true) do
script.Parent.Transparency = 1
wait(1)
script.Parent.Transparency = 0
wait(1)
end
it will only flash its parent (the Checkpoint).

Roblox Studio- Infinite yield possible

I am trying to code a FPS Game but when I tap the button to pick a gun it does not give it to me but instead says Infinite yield possible, anyways this is my code:
game.ReplicatedStorage.RemoteEvents.AKEvent.OnServerEvent:Connect(function(player)
local ak = game.ReplicatedStorage.Weapons.AK:Clone()
ak.Parent = player:WaitForChild("BackPack")
end)
In very little time I have already found what happened, so if it happens to you:
Backpack had a capital P and it was meant to be with a lower case P lol!

Roblox Leaderstats not updating/only updating once

Roblox Leaderstats aren't updating correctly.
When told to update leaderstats, it sometimes doesn't update, and other times, it only updates once.
Code is below:
game.ReplicatedStorage.sleep.OnServerEvent:Connect(function(plr)
local en = plr.leaderstats.Energy
en.Value += 1
print(en.value)
wait()
local speed = 5.07 * ((en.Value / 10) + 1)
plr.Character:WaitForChild("Humanoid").WalkSpeed = speed
print(speed)
end)
On times it doesn't update, the print(en.value) says 1 while the leaderstat stays as 0.
When leaderstat only updates once, the print only updates once as well.
Edit: The leaderstat was defined/created in a previous script.
I completely forgot to answer this, but I am using +=, you would assume it would add to the current amount as the hint says, but it doesn't
Old Code: en.Value += 1
What I do now: en.Value = en.Value + 1
You are declaring the "en" variable right before you add one to the value in this function. This means that every time you run this code, you will reset the "en" variable. If you declare the variable outside of the scope of this function, it should get rid of your issues.

Roblox - detect if mesh is hit by hand

I am not sure where to start so asking for some help. I want to create a script that detect if a certain mesh is hit by players right hand. Every time the mesh is hit I want to increase points for player by 1.
Anyone who can nudge me in the right direction here?
Thanks!
EDIT:
I have added this script in StarterCharacterScripts:
game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
local part1 = workspace.CoinsClouds["Meshes/SackOfGoldNoCoins1"]
part1.Touched:Connect(function(hit)
if hit.Name == "RightHand" then
print(hit.Name)
end
end)
end)
This will register when I bump into the part with the right hand, BUT it will register it 5-20 times in a split second every time I bump into the part with the right hand. See attached image. Anyone know why? I would like it to register only once when the right hand is bumped against the part, or even better, only when the user punch the part/mesh. I have tried to add a wait after RightHand is found, but that doesn't work.
PS! I don't know if this is the right way to script it...
Below is an example of the code you would use. It will check if your part is touched by either the right or left hand and it will run whatever is inside of your if statement, in this case it will increase whatever your score is by 1.
local part = workspace.Part -- reference the part here
local debounce = false --used to check for debounce
part.Touched:Connect(function(hit)
if hit.Name == "RightHand" or "LeftHand" then -- checks if a hand touched it
if not debounce then --Check that debounce variable is not true
debounce = true --currently touching the part
print("hit")
wait(1)
debounce = false
end
end
end)
In relation to your new question it is to do with debounce. Roblox has an entire article on it here: https://developer.roblox.com/en-us/articles/Debounce
Basically you would have to add a new if statement to check that the player isn't already touching this part if it is it wont repeat the what is inside the if statement. The code sample above has been edited to work with debounce.

NSStream Event Timer - iPhone

All,
Is there a way to have a minimum time to keep a stream open before it closes? For some reason, my stream is closing prematurely which is causing errors elsewhere. I need to keep it open to make sure ALL of the data is gathered, and then it can run the other code.
Thanks,
James
In the case that someone falls upon this question later, I ended up creating nested if statements to pull it off.
Basically, there is one statement that checks if the end tag is not found (for my code, the END of the ENTIRE data that I should be receiving is </SessionData> - So, I did if([outputString rangeOfString:#"</SessionData>"].location == NSNotFound). I created a string called totalOutput that would have the outputString added onto the end of totalOutput until the </SessionData> is found.
If anyone ever needs help, just go ahead and comment on here and I can give more information.