Ur script don’t work too ( 30 letters)
Like apo said, try my script with a local script.
Don’t work even if local script
workspace.StandartPepsi.Touched:Connect(function(hit)
instead do
workspace.StandardPepsi.Touched:Connect(function(hit)
i think the man spelt his variable wrong
local Players = game:GetService("Players")
local tool = game.ServerStorage.Pepsi
local debugvalue = 0
if debugvalue == 0 then
workspace.StandartPepsi.Touched:Connect(function(hit)
if hit.Parent then
local Player = Players[hit.Parent.Name]
debugvalue = debugvalue + 1
local toolclone = tool:Clone()
toolclone.Parent = Player.Backpack
end
end)
end
Try this.
This should be a server script.
Localscripts cant be in workspace. put it in startergui
This works, but it clones very much, i need only one tool
Ok so add a debounce. I can make a demo for you if you like.
Example:
local Players = game:GetService("Players")
local tool = game.ServerStorage.TestTool
local debugvalue = 0
local Debounce = false
if debugvalue == 0 then
workspace.Test.Touched:Connect(function(hit)
if hit.Parent and Debounce == false then
Debounce = true
local Player = Players[hit.Parent.Name]
debugvalue = debugvalue + 1
local toolclone = tool:Clone()
toolclone.Parent = Player.Backpack
wait(5)
Debounce = false
end
end)
end
Ok my error fixed:
local Players = game:GetService("Players")
local tool = game.ServerStorage.Pepsi
local debugvalue = 0
local Debounce = false
if debugvalue == 0 then
workspace.StandartPepsi.Touched:Connect(function(hit)
if hit.Parent and Debounce == false then
Debounce = true
local Player = Players[hit.Parent.Name]
debugvalue = debugvalue + 1
local toolclone = tool:Clone()
toolclone.Parent = Player.Backpack
wait(5)
Debounce = false
end
end)
end
Is it a model or single part (30)
This works thank you! But i wanna know one more thing, how do i make tool saves when player leave?
MeshPart, but it’s works anyways
Use this script. I feel like this is the best method if you want to use a localscript.
Put this script anywhere in StarterGui
Also put your tool in ReplicatedStorage
local Debounce == false
local Player = game.Players.LocalPlayer
local tool = game.ReplicatedStorage:WaitForChild("TestTool")
workspace.StandartPepsi.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Name == Player.Name and Debounce == false then
local Debounce = true
local toolclone = tool:Clone()
toolclone.Parent = Player:WaitForChild("Backpack")
wait(3)
local Debounce = false
end
end)
end
Jk apo script works already , so i don’t need it
Ok so, what you need to do is use the following services: DataStoreService
Save the name of the tool, then upon rejoining find the tool in server storage and if the data store says the player has the tool clone it into their Backpack.
Good info, but i even don’t know how to write that
Something like this should work:
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local DataStore = DataStoreService:GetDataStore("ToolData")
local ToolName = "" -- Name of tool
local function OnPlayerAdded(player)
local Data
local success, err = pcall(function()
Data = DataStore:GetAsync(player.UserId.."-Data")
end)
if Data ~= nil then
if ServerStorage:FindFirstChild(Data) then
local Item = ServerStorage:FindFirstChild(Data)
Item:Clone().Parent = player.Backpack
end
else
print("New Player")
end
end
local function OnPlayerRemoving(player)
if player:FindFirstChild(ToolName) then
local Tool = player:FindFirstChild(ToolName)
local success, err = pcall(function()
DataStore:SetAsync(player.UserId.."-Data", Tool.Name)
end)
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
In the tool name variable make sure to provide the correct tool name. This needs to be a server script.
Wait where do i put that script?