If you won’t provide a place file, can we at least see the way you have set everything out in the explorer?
Can you provide a .rblx file with the essential parts needed for it to work?
Make sure Disabled
is not true
.
Its necessary that you check the touched part especially if he’s checking for the other part to have a humanoid backing it so that the player can earn stats in his game. If he doesn’t check that a parts parent is a player then it would error out the game and with enough could cause lots of lag seeing as its a touched function with no debounce
Why not put it in the Handle? Or the part which should be registering the hits?
local debounce = false
local cooldown = 5
local function onTouch(hit)
if debounce == true then return end
debounce = true
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if not Humanoid then -- if it touches accessories
Humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
if not Humanoid then
debounce = false
return
end
end
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Leaderstats = Player:WaitForChild("leaderstats") -- fill in with the name of the leaderstats
local ExpPoints = Leaderstats:WaitForChild("Exp") -- fill in the name of the what I think is IntValue
ExpPoints.Value = ExpPoints.Value + 10
wait(cooldown)
debounce = false
end
script.Parent:FindFirstChild("Tool").Handle.Touched:Connect(onTouch) -- script should be parented to the part of the tool
If you insist setting the parent to StarterCharacterScripts
, here’s the updated version.
Unfortunately it’s doing nothing.
Currently no one can help you any further without unrealistically speculating the problem. The only real way to move forward now is if you could provide a small place file, not the while game, and allow us to take a full look at the issue.
This is dragging somewhat too long, can you send a copy of the place to me or a TC so I can look into the issue behind it?
Server Scripts won’t run in StarterPlayerCharacter
Actually they do. My damage script works perfectly fine.
I’m still really confused on what’s going on here. I created a small little Baseplate file that seems to have everything work perfectly? It’s here:
AwesomelyDeveloper.rbxl (22.0 KB)
Umm it doesn’t work when I test it out…?!
Okay, I fixed up a thing or two, but I now see your issue. Out of curiosity, why exactly is the script parented to StarterCharacterScripts? I don’t see a reason why it wouldn’t be parented to ServerScriptService and slightly modified to get the correct children. Try this game file: AwesomelyDeveloper.rbxl (203.4 KB)
, You’ll see that ‘Script is running’ is printed, but when you ‘touch’ something, it won’t print the full name. When you reset however, it will. I’ll try with this script under ServerScriptService now.
edit: This works with a script under ServerScriptService
print('Script is running')
local function onTouch(hit)
print(hit:GetFullName())
if not hit.Parent then
return
end
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if not Humanoid then -- if it touches accessories
Humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
if not Humanoid then
return
end
end
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Leaderstats = Player:WaitForChild("leaderstats") -- fill in with the name of the leaderstats
local ExpPoints = Leaderstats:WaitForChild("Exp") -- fill in the name of the what I think is IntValue
ExpPoints.Value = ExpPoints.Value + 10
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character:FindFirstChild("Tool").Handle.Touched:Connect(onTouch) -- script should be parented to the part of the tool
end)
end)
The point is that you’re not supposed to index touched_part.Parent
until you validate that it exists.
This code is incorrect, first you’ll want to check if hit.Parent
is not nil
, and then proceeed as normal.
Fixed, I didn’t even read the Touched code, just used another example. Thanks!
I gave a file to @Operatik and it looks like he fixed it! Thank you and thanks to all who tried to help!
EDIT He added a debounce in the script and a leaderstats inside of it.
Out of curiosity, what did he do?
In the future (and for this thread), please explain the solution you found or were given if you mark your own post as solved. Others may have the same situation and posting it will help them out.
local debounce = false
local cooldown = 5
local function onTouch(hit)
if debounce == true then return end
debounce = true
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if not Humanoid then -- if it touches accessories
Humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
if not Humanoid then
debounce = false
return
end
end
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Leaderstats = Player:WaitForChild("leaderstats") -- fill in with the name of the leaderstats
local ExpPoints = Leaderstats:WaitForChild("Exp") -- fill in the name of the what I think is IntValue
ExpPoints.Value = ExpPoints.Value + 10
wait(cooldown)
debounce = false
end
script.Parent.Tool.Handle.Touched:Connect(onTouch) -- script should be parented to the part of the tool
Consider this the solution.