When I am near of a (shop assistant) NPC in my game If i have a weapon in my hand NPC to do a animation like hands up (I have already one animation) and if I don t have a weapon in my hand to can to buy from the shop And to can to rob just once per day if you stolled the shop at clock 14:30 to can to rob again tomorrow at 14:30 scripts:Money Giver
local debounce = false local playerfound = false
function CreateRegion3FromPart(Part) return Region3.new(Part.Position- (Part.Size/2) ,Part.Position+ (Part.Size/2)) end
function GetPlayersInPart(part) local region = CreateRegion3FromPart(part) local partsInRegion = workspace:FindPartsInRegion3(region,nil,math.huge) local players = { }
for i,Part in pairs(partsInRegion) do local player = game.Players:GetPlayerFromCharacter(Part.Parent) if player then for i, v in pairs(players) do if players[i].Name == player.Name then playerfound = true end end if playerfound == false then table.insert(players,player) end playerfound = false end end for i, v in pairs(players) do if players[i].Robbing.Value == false then game.ReplicatedStorage.ShowRobberyGUI:FireClient(players[i]) end players[i].Robbing.Value = true if players[i].CashCollected.Value < 3000 then players[i].CashCollected.Value = players[i].CashCollected.Value + 50 end
end return players end while wait(0.5) do GetPlayersInPart(game.Workspace.Detector) end
******(LocalScript) is in RobberyGui is in StarterGui******
game.ReplicatedStorage.ShowRobberyGUI.OnClientEvent:Connect(function() script.Parent.Frame.Visible = true end) game.ReplicatedStorage.HideRobberyGUI.OnClientEvent:Connect(function() script.Parent.Frame.Visible = false end)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ****(Local Script)is in CashCollected is in Frame is in RobberyGui in StarterGui*** +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
player = game.Players.LocalPlayer
script.Parent.Text = "$".. player:WaitForChild("CashCollected").Value
player:WaitForChild("CashCollected").Changed:Connect(function() script.Parent.Text = "$".. player:WaitForChild("CashCollected").Value end)
*****(Script) is in DoorDetector is in Workspace********
local debounce = false
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.Robbing.Value == true then game.ReplicatedStorage.HideRobberyGUI:FireClient(player) player.leaderstats.Money.Value = player.leaderstats.Money.Value + player.CashCollected.Value player.CashCollected.Value = 0 player.Robbing.Value = false end end end)
(In ReplicatedStorage are 2 RemoteEvents) HideRobberyGUI and ShowRobberyGUI
***Detector is a part in workspace****