What do you want to achieve?
I’ve been trying for hours to rewrite my script for it to work & not have any errors; however, everything I seem to try doesn’t work.
What I want to happen is if the player touches a part with a tool while the BoolValue = true, they receive money and the tool is removed from their inventory and goes back to ServerStorage.
local tool = game.ServerStorage["Straightener"]
local giver = game.Workspace.StraightenerP
local prp = script.Parent
local customer = prp.Parent
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name == 'Straightener' and
if game.StarterPlayer["Straight"].Value == true then
player.leaderstats.Money.Value == player.leaderstats.Money.Value + 25
game.StarterPlayer["Straight"].Value == false
tool.Parent = game.ServerStorage
end
end)
This ServerScript is in the part that the player has to touch with the tool.
I’m very new to scripting so I’m sorry if my script looks like straight garbage
== is for checking, = is for setting.
Change your == to =, since you’re setting the value.
Also, you can use Value += Amount instead of Value = Value + Amount.
Also, you need to define player, you can use the Players:GetPlayerFromCharacter function.
You need to define your tool as well.
On top of that, you are modifying the StarterGui, you need to modify the player’s PlayerGui, and this should be done on the client-side. And again, you are using == instead of =.
You need a PlayerObject, which you can get from the Tool’s Parent and using PlayerService:GetPlayerFromCharacter()
Make sure to wrap that in a variable and to define PlayerService with game:GetService(“Players”)
== is for reading, = is for putting a new value, like @Syclya said
No errors in the Output (thank you for asking though, I forgot to check)
I also revised the script but I’m still getting errors
local tool = game.ServerStorage["Straightener"]
local giver = game.Workspace.StraightenerP
local prp = script.Parent
local customer = prp.Parent
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name = 'Straightener' and game.StarterPlayer["Straight"].Value = true then
game.Players:GetPlayerFromCharacter("leaderstats").Money.Value += 25
game.StarterPlayer["Straight"].Value = false
tool.Parent = game.ServerStorage
end
end)
local tool = game.ServerStorage["Straightener"]
local giver = game.Workspace.StraightenerP
local prp = script.Parent
local customer = prp.Parent
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name = 'Straightener' and game.StarterPlayer["Straight"].Value = true then
game.Players:GetPlayerFromCharacter("leaderstats").Money.Value += 25
game.StarterPlayer["Straight"].Value = false
tool.Parent = game.ServerStorage
end
end)
local tool = game.ServerStorage["Straightener"]
local giver = game.Workspace.StraightenerP
local prp = script.Parent
local customer = prp.Parent
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name == 'Straightener' and game.StarterPlayer["Straight"].Value == true then
game.Players:GetPlayerFromCharacter(Hit.Parent.Parent).leaderstats.Money.Value += 25
game.StarterPlayer["Straight"].Value = false
tool.Parent = game.ServerStorage
end
end)
Honestly, I would recommend you clone the tool outside, and destroy it when finished instead of using the same tool
If you want to check if something is equal to something else then you use 2 equals signs like this: ==
If you set a value to something you use only one equal sign. If you want to get a player from the character with your script then simply do local Character = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent) ← this only works IF the Hit part is a direct child of the character though so you want to check if the Character is nil, so you can do “local Character = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent) if Character ~= nil then … your code here … end”
The tool name check does already this, and since tools are inside character, it is valid and can be expected that the character is outside and free to be used.
Technically, the players character is existant which means theyre in the game, however this would be a case if the original poster’s scripting style was different.
Overall a good point, but I do what the original poster askes.
This will run whenever the .Touched event fires, it can fire if it touches another part (that is not a descendant of the player instance), which will then result in an error.
Just letting you know as people might see this topic in the future.
Well of course. And yes, I do know these basics after being a scripter for years. However, I usually do what the original poster wants to do and keep their own style so they can learn from it.