local RunService = game:GetService('RunService')
local function onHeartbeat()
local cameraPos = game.Workspace.Camera.CFrame.Position -- Also tried with Workspace.currentCamera
print(cameraPos)
end
RunService.Heartbeat:Connect(onHeartbeat)
Why is the printed value always the same even if the player (and therefore also the camera?) moves?
Testing in Roblox Studio often makes it a little difficult to distinguish between the view from the client and server. When your character is running around, and the camera is following your player, you are seeing the view from your client.
The server also has access to the workspace camera, but with nothing to drive it around, it remains stationary. You can see this when you play by going to the Test tab, and clicking on the Current : Client button to toggle over to the server view.
Your Script runs on the server, so it is always checking the server's version of the camera, which is stationary. However, if you were to move this code into a LocalScript in StarterPlayerScripts, you'd see that the position of the player's workspace camera updates the way you would expect.
Related
I am working with User Input Service to make a snake game within Roblox, and the event, Input Began, is not firing. I even copied code from the official Roblox website to teach how to script, and nothing happened. What could be going wrong?
UserInputService only works in LocalScripts, and according to the docs :
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service
Double check that your LocalScript is in one of those locations and that it is not Disabled.
I'm trying to develop a rhythm game in Monogame. The notes are frame rate independent and work consistently over different computers, but the song playing does not. Right now I have it hooked up so the notes spawn and MediaPlayer.Play() do not start until I hit a key (so it's outside of loadcontent/initialize like I've seen other solutions suggest). The song does not start playing until I hit the "I" key (gets checked in Update). However, the song seems to start playing at different times across different devices. I pull down the project on both my laptop (on battery) and desktop, and hit the "I" key at the same time on both, and I get different results on my laptop. Sometimes it'll be seconds ahead of the desktop, other times it'll be a second or two behind (this is usually the case). It seems pretty consistent on desktop. I'd try more than a dozen times and everything is still synced, but not on my laptop. I'm worried this is something that works only on my PC but not on others.
I've tried enabling fixedTimeStep and setting FPS to 60 (and setting the TargetElapsedTime to the window title ensuring that they are indeed both hitting 60) and I still get inconsistent results. I've read from other answers about using PlayPosition from the MediaPlayer class, but that property is readonly so I'm not quite how I could use that.
At first, I thought my notes were simply dependent on frame rate, but after setting FPS and fixedTimeStep, and also holding my laptop up to my desktop monitor they match up perfectly. It's just the song not syncing up. I'm still a newbie to XNA but I couldn't find anyone else reporting different song starting timings like this. Any help would be greatly appreciated.
I thought of a solution the second I got out of bed the next morning. I figured there must be some overhead on MediaPlayer.Play(), but I wondered if I could start it, pause it, then resume instead. Turns out, there is a Pause() and Resume() method which is what what missing from making this work.
So! If anyone else out there is having similar issues, here's what I did. I kept a key to activate MediaPlayer.Play(), but immediately added MediaPlayer.Pause() after. Then I got another key to resume the song, and the notes spawned when the song was resumed. So pressing "I" played the song and paused it immediately. Pressing "R" resumed the song and started spawning the notes.
I have run into a slight issue with my map. I have given the local player some gear by cloning it out of ReplicatedStorage and into their backpack. For some strange reason though, the gear only shows up to the player holding it, and other players on the same server do not see the gear. I have run a test locally and taken a picture to illustrate:
link to image
After you click on the link you can see what I mean. There are two players right next to each other and one of them is holding a torch, but you can only see it on his screen. Here is the script I use whenever I am giving a player a torch:
local player = game.Players.LocalPlayer
local torch = ReplicatedStorage.Gear.Torch
local backpack = player:WaitForChild("Backpack")
torch:Clone().Parent = backpack
As you can see I simply clone the torch out of replicated storage and into the player's backpack. My question is this, do I need to place the torch in some sort of replicated storage for all the other players to be able to see it?
Roblox's documentation on these types of things is quite scarce, so I apologize in advance for not being able to find what is causing this yet. If anyone else has had a similar issue and solved it, some insight would be greatly appreciated. Also, if I need to give more information, please ask and I will provide it.
Thank you in advance!
This is due to networking and preventing players from modifying the server values from local scripts.
Due to this you should focus on having the tool inserted into the backpack from a server script not a local script.
game:GetService('Players').PlayerAdded:Connect(function(player) -- Creates an event that triggers on player joins the server
player.CharacterAdded:Connect(function(character) -- Everytime player spawns run code below
local torch = ReplicatedStorage.Gear.Torch
local backpack = player:WaitForChild("Backpack")
torch:Clone().Parent = backpack
end)
end)
end)
Have this in a script in ServerScriptService.
Let's say I have a turn based match with two players. At some point player 1 recognizes that he is about to lose the game. When it is Player 1's turn, he uses Game Center App to do a swipe to remove the match.
Issues:
A. Take turn timer never expires on Player 1. So the match's turn will not switch to Player 2 when the time expired.
B. The game also offers a view only mode so players can view the game progress while he is out of turn. But since no status was updated to indicate that Player 1 had removed the match manually. App can offers no resolution. Also, you can only end match while it is your turn.
Ideally, I want to declare Player 2 as a winner and end the match.
How do you handle in this situation?
I finally found a workaround for this.
If you delete a match, then call GKTurnBasedMatch:loadMatchesWithCompletionHandler, the deleted match doesn't appear (as expected). However, it turns out that you can still re-download the deleted match using GKTurnBasedMatch:LoadMatchWithID, if you happen to still have the deleted match's ID.
I think we can reasonably assume that The Cheater is going to play the game again; otherwise, why would they care about incurring a loss? Therefore, I implemented the following:
Maintain a table locally, on the device, of matches.
On startup, pull the list of local player's matches from Game Center and compare against my local list.
When The Cheater recognizes the situation and deletes the match using the Game Center interface, the match is removed from Game Center, but not from my local DB. When The Cheater starts my game again, I see that they have more matches locally than on Game Center.
I then call either participantQuitInTurnWithOutcome or participantQuitOutOfTurnWithOutcome, as appropriate, with an outcome of GKTurnBasedMatchOutcomeLost.
This passes the turn to the next player and records a loss for The Cheater. It won't work if the cheater never plays the game again, though. (But, if they're not playing, they're not wrecking any more matches, so the chaos is contained)
I have a delphi app that takes snapshots from a webcam at 1 sec intervals. On the development PC it goes fine, but on the target platform (Atom-based tablet PC running embedded Windows 7 with a different camera) it is extremely flaky. After a reboot and the first time the app is run, it normally manages to initialise the webcam OK and get regular frames from it, but the next time the app is run, it fails to locate the webcam driver, and also pops up a dialog asking me to specify the video source, presumably because it can't find one..
My question: I'm sure this is related to video capture API calls not being in the right order or something, but is there a tool (like wireshark) that will enable me to sniff the API calls, so I can compare what is happening on the embedded Windows 7 system to the XP development system that works?
I am using the following calls/messages:
Initialisation:
capCreateCaptureWindow
WM_CAP_DRIVER_CONNECT
WM_CAP_SET_PREVIEW (false)
WM_CAP_SET_VIDEOFORMAT (as camera after boot is in format I can't handle)
WM_CAP_GET_VIDEOFORMAT
On 1 sec timer:
WM_CAP_SET_CALLBACK_FRAME
WM_CAP_GRAB_FRAME_NOSTOP
On callback:
WM_CAP_SET_CALLBACK_FRAME (nil)
On finish:
WM_CAP_ABORT
WM_CAP_STOP
WM_CAP_DRIVER_DISCONNECT
The first step is a lot easier: Did you make absolutely sure you have the same driver?
It might also be that the sequence of detect - start acquisition is too fast for this slow system. See if introducing a few secs sleep inbetween helps