Basically I want a script that gives you a gear from Lighting when you touch a certain part, then removes that part you just touched.
The gear in Lighting and part in Workspace also have a StringValue inside of them.
The value inside of the gear in Lighting is blank, as I want it to copy the value from the part in the Workspace.
I can somewhat get the script to work when it is inside of the part, but not at all when the script is in the Workspace. The most it has done is give me the item..
Current Script: (Inside of Workspace)
function touch(hit) local item2 = game.Lighting.Storage.MountainDew local debounce = false script.Parent.Touched:connect(function(part) if hit.Name == game.Workspace:FindFirstChild("MountainDew") ~= true then local player = game.Players:GetPlayerFromCharacter(part.Parent) if player ~= nil then if player.Backpack ~= nil then if debounce == false then debounce = true item2:Clone().Parent = player.Backpack hit.Name = "To: " .. (game.MountainDew.House.Value) hit.House.Value = game.MountainDew.House.Value game.Workspace.MountainDew:remove() wait(3) debounce = false end end end end end) end script.Parent.Touched:connect(touch)
Im so confused on why it's not working. If anyone could help, that would be great.
Hey I have a super simple model on this and I'll send you the script I used, It requires putting the tool in ReplicatedStorage, you can edit the script around.
Heres the link to the model: https://www.roblox.com/library/5349028096/Easily-Customisable-Giver
Heres the script:
local Debounce = false script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent)and Debounce == false then local Tool = game.ReplicatedStorage:FindFirstChildOfClass("Tool") local Player = game.Players:GetPlayerFromCharacter(hit.Parent) local NewTool = Tool:Clone() NewTool.Parent = Player.Backpack Debounce = true wait(3) Debounce = false end end)
Where I put FindFirstChildOfClass("Tool")
, You can put your tool name.
Put the tool in ServerStorage
-- define variables local touchPart = game.Workspace.part local tool = game.ServerStorage.MountianDew local toolClone = tool:Clone() local cooldown = false -- execute event and function touchPart.touched:Connect(function(partTouched) if cooldown == true then print("cooldown") else local char = partTouched.Parent toolClone.Parent = char cooldown = true wait(5) cooldown = false end end)
The "MountainDew" tool needs to be placed in game.Lighting. The script below needs to be put in the part. I have also added comments to explain the script
Deb = false --Debounce (In seconds) script.Parent.Touched:Connect(function(Hit) --on hit if Hit.Parent:FindFirstChild("Humanoid") and Deb == false then --checks if it's a player and if debounce is false Deb = true --if it's false and humanoid exists, then it puts Deb to true local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) --gets the player from the character (The character is in game.Workspace) game.Lighting.MountainDew:Clone().Parent = Player.Backpack --clones the mountain dew in lighting and puts it in the player's backpack wait(3)--wait 3 seconds Deb = false --puts Debounce to false end end)