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: Trying to fix this DataStore script, help?

Previous Thread :: Next Thread 
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
10 Apr 2014 06:18 PM
-- the whole purpose of this script, is so that when a player touches either red or green brick, it will update the color that was set to the player.


local data = game:GetService("DataStoreService")
local color = data:GetDataStore("Color")

touched = false

game.Players.PlayerAdded:connect(function(p)
--getting the stored data
getcolor = color:GetAsync("User_" .. p.userId) or "No color yet"
while getcolor do
wait()
print(color)
if getcolor == "No color yet" then
game.Workspace.Display.BrickColor = BrickColor.new("White")
elseif getcolor == "Green" then
game.Workspace.Display.BrickColor = BrickColor.new("Lime green")
elseif getcolor == "Red" then
game.Workspace.Display.BrickColor = BrickColor.new("Really red")
else
print("what the heck is wrong?")
end

end

game.Green.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if touched == false then
touched = true
color:SetAsync("User_" .. player.userId, "Green")
print("Currently in the Touched event for green .. ")
wait(1)
touched = false
end
end)
game.Red.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if touched == false then
touched = true
color:SetAsync("User_" .. player.userId, "Red")
print("Currently in the Touched event for red .. ")
wait(1)
touched = false
end
end)
end)
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
10 Apr 2014 06:19 PM
too lazy 2 read
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
10 Apr 2014 06:20 PM
well, even when i touch the brick, it doesnt update the value...
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
10 Apr 2014 06:21 PM
wait, im stupid.. I said 'color' instead of 'getcolor'
Report Abuse
TomsGames is online. TomsGames
Joined: 11 Oct 2013
Total Posts: 1615
10 Apr 2014 06:25 PM
local data = game:GetService("DataStoreService")
local color = data:GetDataStore("Color")

touched = false

game.Players.PlayerAdded:connect(function(p)
--getting the stored data
getcolor = color:GetAsync("User_" .. p.userId) or "No color yet"
while getcolor do
wait()
print(color)
if getcolor == "No color yet" then
game.Workspace.Display.BrickColor = BrickColor.new("White")
elseif getcolor == "Green" then
game.Workspace.Display.BrickColor = BrickColor.new("Lime green")
elseif getcolor == "Red" then
game.Workspace.Display.BrickColor = BrickColor.new("Really red")
else
print("what the heck is wrong?")
end

end

game.Workspace.Green.Touched:connect(function(hit) -- You forgot to add "Workspace"
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if touched == false then
touched = true
color:SetAsync("User_" .. player.userId, "Green")
print("Currently in the Touched event for green .. ")
wait(1)
touched = false
end
end)
game.Red.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if touched == false then
touched = true
color:SetAsync("User_" .. player.userId, "Red")
print("Currently in the Touched event for red .. ")
wait(1)
touched = false
end
end)
end)
Report Abuse
TomsGames is online. TomsGames
Joined: 11 Oct 2013
Total Posts: 1615
10 Apr 2014 06:26 PM
Same for the third function. Add "game.Workspace.Red"
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
10 Apr 2014 06:28 PM
Haven't tested it yet, but still very thankful for pointing it out!
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