local Players = game:GetService("Players") local function onPartTouch(otherPart) local partParent = otherPart.Parent local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") local player = Players:GetPlayerFromCharacter(partParent) if humanoid then if player.TokenFile.WaterfallToken1.Value == false then script.Parent.Transparency = 1 script.Parent.CanCollide = false local leaderstats = player.leaderstats local findcoins = leaderstats and leaderstats:FindFirstChild("coinz") local coinz4m = math.random(10,50) if findcoins then findcoins.Value = findcoins.Value + coinz4m player.TokenFile.WaterfallToken1.Value = true end end end end script.Parent.Touched:Connect(onPartTouch)
Not sure if I'm accessing the model or the player in game.Players. It should be game.Players though. If you need any other scripts such as the leaderstats scripts, i'd be happy to supply them. I'm also not getting any errors, works fine without the
if player.TokenFile.WaterfallToken1.Value == false then --code here end
but it is kind of a critical part of what I'm working on.
You gotta check if the part's parent is actually the player 'cause sometimes the part touches the ground and stuff. Simply add an operator on line 9:
if humanoid and player then
Let me know if this works.
~Other Relating Scripts~
Waterfall Token Script
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("MoneyStats") game.Players.PlayerAdded:Connect(function(Player) local Leaderstats = Instance.new("Folder", Player) Leaderstats.Name = "TokenFile" local WCrate = Instance.new("BoolValue", Leaderstats) WCrate.Name = "WaterfallToken1" WCrate.Value = false --WCrate2 local WCrate2 = Instance.new("BoolValue", Leaderstats) WCrate2.Name = "WaterfallToken2" WCrate2.Value = false local Data = DataStore:GetAsync(Player.UserId) if Data then WCrate.Value = Data end -- WCrate2 local Data = DataStore:GetAsync(Player.UserId) if Data then WCrate2.Value = Data end end) game.Players.PlayerRemoving:Connect(function(Player) DataStore:SetAsync(Player.UserId, Player.TokenFile.WaterfallToken1.Value) -- Change "Money" with your currency. end) ---WCrate2 game.Players.PlayerRemoving:Connect(function(Player) DataStore:SetAsync(Player.UserId, Player.TokenFile.WaterfallToken2.Value) -- Change "Money" with your currency. end)
(intentionally bool value)
coinz leaderstats script
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("MoneyStats") game.Players.PlayerAdded:Connect(function(Player) local Leaderstats = Instance.new("Folder", Player) Leaderstats.Name = "leaderstats" local Currency = Instance.new("IntValue", Leaderstats) Currency.Name = "coinz" Currency.Value = 0 local Data = DataStore:GetAsync(Player.UserId) if Data then Currency.Value = Data end end) game.Players.PlayerRemoving:Connect(function(Player) DataStore:SetAsync(Player.UserId, Player.leaderstats.coinz.Value) end)