Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

HELP PLEASE MY SCRIPT HAS A ERROR AND I'M STUCK?

Im a Bad scripter and a Very beginner one, i was copying a Alvin Blox vid on yt and on line 43 of my code i had a error >:( it said expected identifer when parsing, got ')' on my end) i marked the error with ERROR --> Can You Anyone help?!?!

Script:


local dataStores = game:GetService("DataStoreService"):GetDataStore("CashDataStore")
local defaultCash = 0
local playersLeft = 0

game.Players.PlayerAdded:Connect(function(player)
		
		playersLeft = playersLeft + 1
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local bucks = Instance.new("IntValue")
	bucks.Name = "Cash"
	bucks.Value = 0
	bucks.Parent = leaderstats
	
end)

player.CharacterAdded:Connect(function(character)
	character.Humaniod.WalkSpeed = 16	
end)

	character.Humanoid.Died:Connect(function()
		
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
			end
			
			player:LoadCharacter()
end)
	
	local player_data
	
	pcall(function()
		player_data = dataStores:GetAsync(player.UserId.."-Cash")		
     end)
	
	if player_data ~= nil then
		bucks.Value = player_data
		else
			bucks.Value = defualtCash
ERROR HERE--> 	end)

	
	
		
		local bindableEvent = Instance.new("BindableEvent")
		
game.Players.PlayerRemoving:Connect(function(player)
	
	pcall(function()
		dataStores:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value)
		print("Saved")
		playersLeft = playersLeft - 1
		bindableEvent:Fire()
		end)
	
end)
	
game:BindToClose(function()
	
	while playersLeft > 0 do
		bindableEvent.Event:Wait()
	end
end)

5 comments

0
  1. Delete the ) (There would be more step if it still error)
0

when i do that, my function calls underline yellow :(

0

It’s underlining red since all the syntax errors have been resolved. You’re now experiencing a logic problem with your code. You cannot call “player” outside of the PlayerAdded signal since it’s only passed as a parameter in it’s scope, making the CharacterAdded signal invalid. Same issue applies for saying character.Humanoid.Died.

0

Maybe give the link to the Alvin Blox Video so I can try to re-write the script for you.

2 answers

I think that there has to be no ), just end.

1 comment

0

when i do that all my function calls under line orange

Here put this script from the video and see what goes on tell me if it worked. You can change Money to your currency like Cash I see you put that.

local player = game.Players.LocalPlayer

local leaderstats = player:WaitForChild("leaderstats")

local datastore = game:GetService("DataStoreService"):GetDataStore("MoneySave")

local money = leaderstats:WaitForChild("Money")

defaultCash = 10

playersLeft = 0



game.Players.PlayerAdded:Connect(function(player)

 playersLeft = playersLeft +1

 local folder = Instance.new("Folder")

 folder.Parent = player

 folder.Name = "leaderstats"

 

 local money = Instance.new("IntValue")

 money.Parent = folder

 money.Name = "Money"

end)



local player_data

pcall (function()

 player_data:GetAsync(player.UserId.."-Money")

end)



if player_data ~= nil then

 -- Load points in (player not new)

 money.Value = player_data

 

else

 -- New Player

 money.value = defaultCash

end



local bindableEvent = Instance.new("BindableEvent")



game.Players.PlayerRemoving:Connect(function()

 pcall (function()

  datastore:SetAsync(player.UserId.."-Money",player.leaderstats.Money.Value)

  print("Saved")

  playersLeft = playersLeft - 1

  bindableEvent:Fire()

 end)

end)



game:BindToClose(function()

 -- This will be triggered upon shutdown

 while playersLeft > 0 do

  bindableEvent.Event:Wait()

 end

end) 

1 comment

0

So it should still work with all the spaces if it dosent then just push them together but try it normal first. Also check ur Output in Studio when testing.

This discussion is preserved as it was. New answers, comments, and votes are closed.