|
The part works but the message doesn't work.
Output:
13:36:05.190 - Players.Player1.Backpack.Fishing Pole.Line:29: wrong number of arguments
13:36:05.190 - Script 'Players.Player1.Backpack.Fishing Pole.Line', Line 29
13:36:05.191 - Stack End
------------------------------------
local tool = script.Parent
local user
tool.Equipped:connect(function(mouse)
user = tool.Parent
mouse.Button1Down:connect(function()
local ray = Ray.new(tool.ring.CFrame.p, (mouse.Hit.p - tool.ring.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
local distance = (position - tool.ring.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Really Black")
rayPart.Transparency = 0
rayPart.Anchored = true
rayPart.CanCollide = true
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.ring.CFrame.p) * CFrame.new(0, 0, -distance/2)
m = Instance.new("Message")
wait(3)
user.RayPart:Destroy()
m.Parent = game.Workspace
m.Text = math.random("Hey", "Dude", "Sup") -- The problem is here
end)
end) |
|
|
Create a table containing the text as math.random is for numerical values. |
|
domorox17Join Date: 2012-03-06 Post Count: 1710 |
Set the messages as a table, and do
m.Text = tablename[math.random(1,#tablename)] |
|
|
You're replacing number values with text. I'm sure you can use a table, but since I don't have much experience in that specific area of scripting you can do something like this:
text = math.random(1,3)
if text == 1 then
m.Text = "Hey"
elseif text == 2 then
m.Text = "Dude"
elseif text == 3 then
m.Text = "Sup" |
|
domorox17Join Date: 2012-03-06 Post Count: 1710 |
Mine should work fine.... |
|
|
Thanks! The tables worked. I guess I should have thought of that. |
|
|
@Dom, I posted a bit late and didn't see the previous comments. Yours would work perfectly. |
|
|
Frost would have worked just not as efficient. |
|
|
Is there any way for there to be a harder chance to get one of the texts? |
|
|
Increase the range of the math.random. |
|
domorox17Join Date: 2012-03-06 Post Count: 1710 |
Or add ti the tabke and use mine :p |
|
|
|
Can you give me an example? |
|
|
|
|
In my example, I used math.random(1,3). Changing this to something such as math.random(1,20) would decrease the probability of the text showing up. |
|
|
fish = {"You caught a shark!", "You caught a pufferfish!", "You caught a clownfish!", "You caught a Go Fish!", "You caught a mackerel!", "You caught a JellyFish!"}
local tool = script.Parent
local user
tool.Equipped:connect(function(mouse)
user = tool.Parent
mouse.Button1Down:connect(function()
w = 1
if w == 1 then
local ray = Ray.new(tool.ring.CFrame.p, (mouse.Hit.p - tool.ring.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
local distance = (position - tool.ring.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Really Black")
rayPart.Transparency = 0
rayPart.Anchored = true
rayPart.CanCollide = true
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.ring.CFrame.p) * CFrame.new(0, 0, -distance/2)
m = Instance.new("Message")
wait(3)
user.RayPart:Destroy()
m.Parent = game.Workspace
m.Text = fish[math.random(1, #fish)]
wait(2)
m:Destroy()
w = 0
end
end)
end)
So let's say I want Shark to be the least common. How would I do that? |
|
|
I'm not sure how to edit this with your table format, but if you were to use my format as an example I would put ranges for each type of fish.
Example (not functioning code at all):
x = math.random(1,100)
if x > 1 and x < 10 then
sharkie
elseif x > 11 and x < 40 then
fishie
elseif x > 41 and x < 80 then
kapeesh
|
|
|
I'm sticking with tables, as they are more efficient |
|