Hello Developers, today I was working on my game and just messing around trying to have fun improving on my skill of creating games. The game I’m working on is just for fun, although I would like some feedback if you would like to tell me, in the replies. First of all, If you want to play the game and try to tell me what I could improve on, that would be awesome, so I’ll leave a link to the game if you want to try it out. I’ll get to the scripting help in a second.
Let me introduce you to the game I’m working on if you want to play it or not.
Basically, you get put in a container empty on start, there are parts that spawn from the top of the container and you basically need to get to the top and touch the touch detector. When you touch the touch detector on the top, you should get 50 Cash, get reset and every brick will be cleared. as I said this was just for fun and testing.
https://www.roblox.com/games/6544633722/Part-Party
Let’s get to the scripting help.
This should be mentioned, I’m a new scripter and I am not experienced, although I know the basics of Lua. So, here is the problem I have. I basically need to make the touch detector give me 50 Cash when I touch it or someone else does, I made a pretty simple data store script and I’ve encountered some problems along the way of making the Touch detector script that gives you 50 coins. I’ve searched for help all around the internet and still couldn’t find the correct thing I’m looking for to solve.
So, this is the data store script I am using.
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore('MyDataStore')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = 'leaderstats'
local currency = Instance.new("IntValue", leaderstats)
currency.Name = 'Cash'
currency.Value = 0
local PlayerCashId = 'Cash_'..player.UserId
local CashData
local s, err = pcall(function()
CashData = MyDataStore:GetAsync(PlayerCashId)
end)
if s then
currency.Value = CashData
else
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local PlayerCashId = 'Cash_'..player.UserId
local s, err = pcall(function()
MyDataStore:SetAsync(PlayerCashId, player.leaderstats.Cash.Value)
end)
if s then
print('Stored all Player Data')
else
warn(err)
end
end)
You can see that I have an IntValue, A currency Called Cash in my position.
Now I want to make the Touch detector give 50 coins to the player that touches it. The problem is, that I have no idea how to make it do that.
So, This is the touch detector script I’ve made that clears the blocks and works perfectly fine, although I’m sure it could be better.
------------------------------------------------------------ Touch Money Giver (Work in progress)
----------------------------------------------------- Touch Detector Clear Children
wait(160)
local Detector = script.Parent
local SC = game.Workspace.SpawnedBricks.SpawnedCylinders
local SB = game.Workspace.SpawnedBricks.SpawnedBricks1
local SS = game.Workspace.SpawnedBricks.SpawnedSpheres
local SW = game.Workspace.SpawnedBricks.SpawnedWedges
local function Clear()
SB:ClearAllChildren()
SC:ClearAllChildren()
SS:ClearAllChildren()
SW:ClearAllChildren()
end
Detector.Touched:Connect(Clear)
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Health = 0
end
end)
------------------------------------------------------------ nil
As you can see that’s the Part Clearer script I’ve made. The wait(160) is to prevent exploiters from touching the touch detector, and abusing it, to annoy players that just want to have fun.
Now to the Touch detector part that gives the Cash, As I said, I don’t know how to make such a script so I would like to have some help with the replies.
Thanks for reading my post, This is the first time I’ve posted on the dev forum.