So I have this tool in my image label and instead of just giving the teddy I want it to do random, so if there are more than 1 tool in the image label it will choose one of those random, not just the teddy.
here is the script Please edit it if u can:
script.Parent.Touched:Connect(function(hit) --Event fires when the part is tocuhed
if hit.Parent:FindFirstChild("Humanoid") then --Confirms it is a character
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Finds the player
if player.Backpack:FindFirstChild("Tool") == nil then --Change tool to the name of the tool
if player.leaderstats.Cash.Value >= 50 then --Checks for the right amount, change 'Cash' to the name of your stat
game.StarterGui:WaitForChild("ScreenGui").Enabled = true --Change ScreenGui to the Gui name
game.StarterGui.ScreenGui.Parent = player.PlayerGui --Inserts the Gui into the player so only they can see it
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 50 --Subtracting the cash
end
end
end
end)
game.ReplicatedStorage.ToolPurchase.OnServerEvent:Connect(function(player)
if player.Backpack:FindFirstChild("Teddy") then
-- Object is there, do nothing
return
else
local clonedTool = script.Parent.Teddy:Clone()
clonedTool.Parent = player.Backpack
end
end)
script.Parent.MouseButton1Click:Connect(function() --Detects for when a player clicks the Gui
script.Parent.Rotation = math.random(-12,11)
wait(1)
script.Parent.Visible = false
wait(0.001)
script.Parent.Parent.TextLabel.Visible = true
script.Parent.Parent.Teddy.Visible = true
script.Parent.Parent.TextLabel.Text = "You got a Teddy!"
wait(1)
script.Parent.Parent.Teddy.Visible = false
script.Parent.Parent.TextLabel.Visible = false
wait(2)
game.ReplicatedStorage.ToolPurchase:FireServer() --Fires the remote event (change ToolPurchase to the name of the remote event if it is named something different)
end)
- Each script is in it’s own script. nothing is together.