local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
local tools = ServerStorage:FindFirstChild("Tools")
local scripts = ServerStorage:FindFirstChild("Scripts")
local toolConfig = require(ReplicatedStorage:FindFirstChild("Config"):FindFirstChild("ToolConfig"))
remotes.ToolActivated.OnServerEvent:Connect(function(player: Player)
local playerTool = player.inventory.EquippedTool.Value
for tool, toolTable in pairs(toolConfig) do
if tool == playerTool then
player.leaderstats.Decibel.Value += toolTable.Decibel
end
end
print(player.Name)
end)
for _, tool in ipairs(tools:GetChildren()) do
local script = scripts.Click:Clone()
script.Parent = tool
end
This is my code to make the Decibel Value from leaderstats go up
Then It doesn't show any error up but it isn't working.
It doesn't print the player name and also it doesn't make the Decibel Value go up
help
On the client, you need to fire the signal.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
local tool = script.Parent
tool.Activated:Connect(function()
remotes.ToolActivated:Fire()
end
My goal is to have an initial/max custom player health for my Roblox place in Roblox Studio.
To do this I have created a script in StarterPlayer/StarterPlayerScript with the following content:
local DEFAULT_HEALTH = 10
game.Players.PlayerAdded:connect(function(player)
player.character.Humanoid.MaxHealth = DEFAULT_HEALTH
player.character.Humanoid.Health = DEFAULT_HEALTH
end)
I have also tried with:
local DEFAULT_HEALTH = 10
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.MaxHealth = DEFAULT_HEALTH
Humanoid.Health = DEFAULT_HEALTH
in both cases when I playtest it (TEST->PLAY) it seems the default health=100 is used instead of health=10
Is it possible to fix the issue outlined?
The PlayerAdded event fires as soon as the player joins the server, but their character model doesn't load into the world immediately. So you need to wait for the player's character model to spawb. Luckily, you can use the CharacterAdded event to know when that happens.
So using a Script in the Workspace or ServerScriptService, try this :
local DEFAULT_HEALTH = 10
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid.MaxHealth = DEFAULT_HEALTH
character.Humanoid.Health = DEFAULT_HEALTH
end)
end)
Im trying to make it so that it prints out the topplayer's name but it output prints the error on the title.
Heres the code:
local highest = 0
local mostvote = 0
while true do
wait(10)
local TopPlayer
local TopCash = 0
for i, plr in ipairs(game:GetService("Players"):GetChildren()) do
local kills = plr.leaderstats.Kills.Value
if kills >= TopCash then
TopPlayer = plr
TopCash = kills
end
end
print(TopPlayer.." Got the most kills so "..TopPlayer.Team.." wins!")
for i, plr in ipairs(game:GetService("Players"):GetChildren()) do
local kills = plr.leaderstats.Kills.Value
kills.Value = 0
end
end
print(TopPlayer.." Got the most kills so "..TopPlayer.Team.." wins!")
The error tells you what's happening : you've got an Instance of something and you're trying to add a string to it, and it doesn't know what to do with it.
TopPlayer is a Player instance, and you probably want to print out their name. So instead of using the Player instance directly, you should probably use their Name or their DisplayName in the message. Similarly, TopPlayer.Team is a Team instance, and you should probably print its Name as well.
print(TopPlayer.Name .." got the most kills so " .. TopPlayer.Team.Name .. " wins!")
Hello,
I have a shop system that half works. It has one problem. When you buy something from the shop, your money goes down, as it's suppose to. But then if you get more money, the number of your money springs back up to what it was, plus it gives you the new money that you got. I don't know how to fix it. This is the code.
local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
if player.leaderstats:FindFirstChild("Money").Value >= price.Value then
player.leaderstats:FindFirstChild("Money").Value = player.leaderstats:FindFirstChild("Money").Value - price.Value
game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
end
end)
This is the code that puts the item in the inventory:
local tools = game.ReplicatedStorage:WaitForChild("Tools")
game.ReplicatedStorage.ShopBuy.OnServerEvent:Connect(function(player,tool)
local clone = tools:FindFirstChild(tool):Clone()
clone.Parent = player.Backpack
local clone2 = tools:FindFirstChild(tool):Clone()
clone2.Parent = player.StarterGear
end)
Changes made in LocalScripts aren't replicated to everyone. Which means that the changes only appear for you. If you want to update your leaderstats, make the change in a Script.
To fix your problem, move the price check into the Script that is handling the ShopBuy RemoteEvent.
local item = script.Parent.Parent
local shopBuy = game.ReplicatedStorage.ShopBuy
script.Parent.MouseButton1Click:connect(function()
shopBuy:FireServer(item)
end)
Then parse the details in your server Script.
local tools = game.ReplicatedStorage.Tools
local shopBuy = game.ReplicatedStorage.ShopBuy
shopBuy.OnServerEvent:Connect(function(player, item)
-- get some details about the tool
local toolName = item.ItemName.Value
local price = item.Price.Value
local money = player.leaderstats:FindFirstChild("Money")
-- check that the player has enough money
if money.Value >= price then
money.Value = money.Value - price
-- give the tool
local clone = tools:FindFirstChild(toolName):Clone()
clone.Parent = player.Backpack
local clone2 = tools:FindFirstChild(toolName):Clone()
clone2.Parent = player.StarterGear
end
end)
Any working roblox team change GUIs that you have to be in a certain group to change teams in?
Hi there, I've spent 20 minutes to code a team-changing GUI for you, follow my steps below for it to work. (This is FilteringEnabled friendly)
Step 1 Insert a LocalScript into StarterGui
Step 2 Copy the stuff from LocalScript below and paste it into your LocalScript
Step 3 Insert a Script into either Workspace or ServerScriptService (your choice)
Step 4 Copy the stuff from ServerScript below and paste it into your script
ServerScript
local teams = game:GetService("Teams")
local settings = {
["GUIHeight"] = 30, --put in a number over 20, or 100 if you want it to fill the screen
["GUIWidth"] = 40, --put in a number over 20, or 100 if you want it to fill the screen
["GUIColor"] = Color3.fromRGB(240,240,240), --color of the team changer gui
["TitleText"] = "Team Changer", --title text in the gui
["TitleFont"] = "ArialBold", --font of title
}
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.PlayerGui
local plr = game.Players.LocalPlayer
local teamGUI = Instance.new("ScreenGui",plr.PlayerGui)
local frame = Instance.new("Frame",teamGUI)
frame.AnchorPoint,frame.Size,frame.Position,frame.BackgroundColor3 = Vector2.new(0.5,0.5),UDim2.new(settings.GUIWidth/100,0,settings.GUIHeight/100,0),UDim2.new(0.5,0,0.5,0),settings.GUIColor
local title = Instance.new("TextLabel",frame)
title.Text,title.Font,title.Size,title.TextScaled,title.BackgroundTransparency = settings.TitleText,settings.TitleFont,UDim2.new(1,0,0.15,0),true,0.5
local closebutton = Instance.new("TextButton",title)
closebutton.Size,closebutton.Position,closebutton.BackgroundColor3,closebutton.Text = UDim2.new(0.1,0,1,0),UDim2.new(0.9,0,0,0),Color3.fromRGB(255,155,155),"Close"
local list = Instance.new("ScrollingFrame",frame)
list.Size,list.Position,list.BackgroundTransparency = UDim2.new(1,0,0.85,0),UDim2.new(0,0,0.15,0),1
local UILayout = Instance.new("UIListLayout",list)
local serverTeamHandler = game.ReplicatedStorage:WaitForChild("teamChanger")
local getTeams = teams:GetChildren() --this part checks if you have teams in your game (you need to have put the teams in your game already)
for i,v in pairs(getTeams) do
print("[Team " .. i .. " found]: " .. v:GetFullName())
local teamButton = Instance.new("TextButton",list)
teamButton.BackgroundColor3 = v.TeamColor.Color
teamButton.Size = UDim2.new(1,0,0,40)
teamButton.Text,teamButton.TextColor3,teamButton.TextStrokeTransparency,teamButton.TextScaled = v.Name,Color3.fromRGB(255,255,255),0.7,true
teamButton.MouseButton1Down:connect(function()
print("You changed teams. You are now in: " .. v.Name)
serverTeamHandler:InvokeServer(v)
end)
end
closebutton.MouseButton1Click:connect(function()
frame:TweenPosition(UDim2.new(0.5,0,2,0),"Out","Quad",0.5)
local returnButton = Instance.new("TextButton",teamGUI)
returnButton.Size,returnButton.Position,returnButton.Text,returnButton.TextScaled = UDim2.new(0,200,0,50),UDim2.new(0.5,-100,1,-50),"Open Team Changer",true
returnButton.MouseButton1Down:connect(function()
returnButton:Destroy()
frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Elastic",1,true)
end)
end)
LocalScript
local teamChanger = Instance.new("RemoteFunction",game.ReplicatedStorage)
teamChanger.Name = "teamChanger"
local function changeTeam(client,team)
print(client.Name .. "changed teams: now in" .. team.Name)
client.Team = team
end
teamChanger.OnServerInvoke = changeTeam
If you followed these steps correctly, you should now have a working team changing GUI in your game! It works as long as you have already inserted Teams in your game. The first few lines in the LocalScript can also be customized as well!